How to find out container version?

I’m looking for a way to find out a container’s version.
% docker ps will show me the tag, but the tag is “latest”, that WAS the latest when I downloaded the container but might not be the latest anymore. So how do I know what is the version of my running constainer? :slight_smile:

There is no such thing as a container’s version.

You can identify an exact image by it’s sha256 digest, use docker image inspect ${image id} --format '{{.RepoDigests}}' to get the digest. If you are lucky, the digest is additionaly referenced by a immutable tag, which in theory might help you to identify the “version” on Dockerhub (manual task)

Though, some maintainers add labels or environment variables to transport version information in their images. It’s a good habit, but nothing that can be expected to be generally available. Use `docker history ${image digest or id}

1 Like

Thank you!
In this case what is the recommended method to find out if I’m running the latest version of a container? How do I know if I should update or not?

1 Like

The latest tag usualy is mutable, thus it points to the recent image’s sha256 digest.

Execute docker pull imagename:tag to pull the latest image for the tag. If it pulls no layer, you can be sure that you already have the current image in your local image cache.

A container is bound to a specific image sha256 digest. You need to remove the container that points to the old image and re-create a new container that points to the current image in your local image cache (this is where all images from docker pull and docker build are stored). All data not persisted in volumes/bind mounts will be lost. Beginners tend to forget them sometimes and are surpised why the last their data…

Thank you!
Let’s say there is a new image but it doesn’t work and I have to roll back, how would I do it? How do I know to which version to roll back?

1 Like

Assumed you still have the “old” image for the tag in your local image cache.
Inspect the old image (for the repository having the tag <none>) with docker image inspect ${image id} --format '{{.RepoDigests}}', then use the returned value (=the RepoDigest) without the wrapping [ and ] charachters in your docker run command or docker-compose.yml instead of the image:tag.

If you don’t use docker-compose yet, it is highly recommended to use it.

update: bloody forum markup is interpreting <none> as html tag which make it invisible - had to wrap it in backticks to keep it visible.

1 Like

That’s awesome, thank you!

If you care about version management of your app or an image that it depends on then NEVER use the the ‘latest’ tag. There is no way you can tell which version you are actually using and whether it’s behaviour is likely to introduce a breaking change. Always using explicit tags, both for your own images and any you use from a public registry. That way you can run multiple versions, roll backwards and forwards, implement blue-green update strategies, do canary testing … and so on. All of that is impossible to do reliably using ‘latest’.

Thank you goffinf, sounds good

Use command:
docker images

choose image id for the docker you want to inspect

Use command:
docker inspect <image_id>

Look in de listing, version number is mentioned several times.