If I create a container using a tag/label

docker run --name some_container -d me/my_image

Update the image with

docker pull me/my_image

And restart the container with

docker restart some_container

Which version does the new container use?

In docker inspect .Image gives the id of the specific image, .Config.Image gives the label.


It uses the image the container was created from. This is pretty easy to verify.

Lets take a look at the image ID for an outdated image:

$ docker images alpine:3.2                 
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
alpine              3.2                 137f13b3ac76        8 seconds ago       5.254 MB

Cool, now lets create a container based off that image:

$ docker create --name test alpine:3.2 sh

We can see the image that container is based off of:

$ docker inspect -f '{{.Image}}' test    

Now we pull an updated alpine:3.2:

$ docker pull alpine:3.2
3.2: Pulling from library/alpine
Digest: sha256:1b42caf22e8a6c00e4e7f8c0274495b815336d549317cf694e274832aecf11ed
Status: Image is up to date for alpine:3.2

See that it has a new image ID:

$ docker images alpine:3.2                 
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
alpine              3.2                 74e49af2062e        3 days ago          5.254 MB

But the container is still using the older image ID:

$ docker inspect -f '{{.Image}}' test

When you check out the images you can see the new one and the old dangling one:

$ docker images
REPOSITORY         TAG                  IMAGE ID            CREATED             VIRTUAL SIZE
<none>             <none>               137f13b3ac76        51 seconds ago      5.254 MB
alpine             3.2                  74e49af2062e        3 days ago          5.254 MB

If you tried to delete the old image you will be met with an error:

$ docker rmi 137f13b3ac76
Error response from daemon: conflict: unable to delete 137f13b3ac76 (must be forced) - image is being used by stopped container 1011a97c6ed5
Error: failed to remove images: [137f13b3ac76]

The image can be deleted once the container that is based off it is removed.

  • Thanks for the answer. I would add the "docker restart" step to your demonstration to make it clear it has been restarted. – Esa Varemo Dec 27 '15 at 22:27
  • I guess I should have. But the distinction here is that the container (started, stopped, restarted, or otherwise) is based on an image ID and the underlying image ID or based filesystem doesn't change unless you commit the changes to a new image or deleted and recreated the container. – Andy Shinn Dec 28 '15 at 1:54
  • It doesn't answer the question itself. When we restart the container, does it start using the newly pulled updated image with ID 74e49af2062e? – Seff Nov 9 '20 at 3:13

[EDIT] I was wrong. The container will use the previous image even we restart it.

We need to delete and re-create the container from the same tag to use the new revision of the image.

  • This is wrong. The image is linked to the container by its hash, not its name. You can easily verify this by running docker inspect some_container |grep Image before and after the restart. Additionally, you'll see that when you run docker image prune -a the newly pulled image will be deleted instead of the older, because the container still uses the older image. – Gerald Schneider Nov 10 '20 at 11:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.