The container commit command

It is important to know that when you are attached to a running container and make changes to it, such as installing new packages, or changing configuration files, that those changes only apply to that running container. If, for example, you use an Ubuntu image to run a container and then install curl into that container, the change does not apply back to the image you ran the container from, in this example, Ubuntu. If you were to start another container from the same Ubuntu image, you would need to install curl again. However, if you want to have the changes you make inside a running container persist and be available when you run new containers, you can use the container commit command. The container commit command allows you to save the current read/write layer of a container along with the layers of the original image, creating a brand new image. When you run containers using the new image, it will include the changes you made and saved with the container commit command. Here is what the container commit command looks like:

# Usage: docker container commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]
docker container commit ubuntu new-ubuntu

And here is an example of using the container commit command to install curl to a running container, and then creating a new container that includes the installed curl command:

With this example, I can now run new containers from the ubuntu-curl image, and all of them will have the curl command already installed.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset