Docker Commit on a existing image

vijaygopal picture vijaygopal · May 28, 2017 · Viewed 13.2k times · Source

Docker commit creates a new image every time commit command is issued. Is it possible to issue commit on currently running container and the changes gets saved to the existing image((existing image here is the image from which the container was spawned)). This way no new image will be created everytime i execute commit.

Please let me know if this is possible ?

Answer

hurturk picture hurturk · May 28, 2017

Using names and tags already updates the image you want. Make sure you put the name of the same image after container id during commit. From the doc:

$ docker ps

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS              NAMES
c3f279d17e0a        ubuntu:12.04        /bin/bash           7 days ago          Up 25 hours                            desperate_dubinsky
197387f1b436        ubuntu:12.04        /bin/bash           7 days ago          Up 25 hours                            focused_hamilton

$ docker commit c3f279d17e0a  svendowideit/testimage:version3

Edit: I highly recommend you to stop the container before proceeding, so you would reduce your chance getting into stale state for the next run. Also, it might be good idea to use a different tag, test it, then re-tag to your real target.

Edit2: As pointed by @MilindDeore, this doesn't physically overwrite the previous image, but re-address the name. So, you might have to do a manual deletion or wait it to be garbage collected (if in place).