Bootstrap FreeKB - Docker - Create a new image from existing image using the docker commit command
Docker - Create a new image from existing image using the docker commit command

Updated:   |  Docker articles

This assumes you have installed Docker on Linux and Docker is running.

Let's say you have used the docker run command to pull down the jeremycanfield/hello-world:latest image and created and started the hello-world container.

docker run --detach jeremycanfield/hello-world:latest --name hello-world

 

In this example, the docker images command should return something like this.

~]# docker images
REPOSITORY    TAG       IMAGE ID       CREATED        SIZE
hello-world   latest    d1165f221234   3 months ago   13.3kB

 

To create a new image from the existing hello-world image, you will make some change to the hello-world container. In this example, the docker exec command is used to create the /foo.txt file in the container.

docker exec hello-world touch /foo.txt

 

The docker commit command can be used to create a new image using the container as the image. In this example, the name of the container is hello-world and the name of the new image is greetings.

docker commit hello-world greetings

 

The docker images command should now show the new image.

~]# docker images
REPOSITORY    TAG       IMAGE ID       CREATED        SIZE
hello-world   latest    d1165f221234   3 months ago   13.3kB
greetings     latest    a8tkf23c8hj    1 minute ago   13.5kB

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 67eacf in the box below so that we can be sure you are a human.