Flux
Flux

Reputation: 10940

How to know which version of an image a container is running?

Suppose I have one running container:

CONTAINER ID   IMAGE            COMMAND   CREATED       STATUS       PORTS                  NAMES
59f00e5c96d6   me/myapp:latest  "bash"    9 hours ago   Up 7 hours   127.0.0.1:80->80/tcp   bashapp

Suppose I found a mysterious docker image archive file me-myapp-latest.tar.gz out of nowhere. I want to know, relative to the image used to start the running container, whether that file contains an older or newer version of the image.

I load the archive into docker using docker load --input me-myapp-latest.tar.gz. docker images now shows:

REPOSITORY   TAG      IMAGE ID        CREATED           SIZE
me/myapp     latest   fe22fc800843    12 hours ago      123MB

This gives no indication of whether or not the me/myapp:latest shown by docker images is the same as that shown by docker ps -a. They are both named me/myapp:latest, but they could be different.

How can I determine if the images are the same, or if they're not the same, which one is newer and which is older?

Upvotes: 3

Views: 2616

Answers (1)

phaebel
phaebel

Reputation: 66

In general, you can check if the imageId of your container matches the one of your image:

docker inspect -f '{{ .Image }}' bashapp

As you won't be able to remove an image that is still used, you should be able to find the image of your container with the following command:

docker images | grep $(docker inspect -f '{{ .Image }}' bashapp | cut -d ":" -f 2 | head -c 12)

If you know which image is used, you should also be able to tell whether the image is newer or not.

Upvotes: 1

Related Questions