Main Content

Save Changes in Containers

If you make changes within a container, you can save the container to a new container image for later use. These changes include:

  • Saving files or data sets inside containers

  • Installing updates, additional toolboxes, or add-ons to MATLAB® inside the container

You can then deploy the updated version of the container without making the changes again.

To save changes, perform these steps after you make your changes in the container and while the container is still running.

Get Container ID

If you are using a remote Docker® host, on your client machine, open another connection to the Docker host, the machine running the container, using PuTTY or the same method you access the Docker host and launch the container. If you are using a local Docker host, open a new shell.

In the new shell or connection, get the container ID of the running container using this command. This command displays the details of all containers currently running. Identify the container that you want to save and take a note of the container ID.

docker ps -a

For example, suppose you are using MATLAB R2020a in a MATLAB Container. You have updated MATLAB in the container you are running, and you want to save it for later use. Find the container ID of the running container using the docker ps -a command.

CONTAINER ID        IMAGE                            COMMAND             CREATED              STATUS              PORTS                                            NAMES
3d555451f07a        nvcr.io/partners/matlab:r2020a   "/bin/run.sh"       24 minutes ago       Up 24 minutes       0.0.0.0:5901->5901/tcp, 0.0.0.0:6080->6080/tcp   relaxed_pasteur
The container ID in this example is 3d555451f07a.

Save Container

To save the container to a new container image, use the docker commit command.

docker commit <containerID> <repository>:<tag>
The docker commit command locally saves a new container image based on the specified container ID. In this case, the command saves the container image based on the currently running container. You can view the images available locally using the docker images command.

Commit the container image and save it with the name mymatlab:r2020a. This command also commits the VNC option. When you next run the saved container, it defaults to using the VNC mode.

docker commit 3d555451f07a mymatlab:r2020a

To open the same container using different modes next time, use the --change flag.

docker commit --change 'ENTRYPOINT ["/bin/run.sh"]' 3d555451f07a mymatlab:r2020a

The previous command saves the container on a Linux® operating system. For other operating systems, use the appropriate quotes. For example, for a Microsoft® Windows® operating system, use this command:

docker commit --change "ENTRYPOINT [\"/bin/run.sh\"]" 3d555451f07a mymatlab:r2020a

You can now launch the updated container image by specifying the tag of the updated container in the docker run command.

Related Topics