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?
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}
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?
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?
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.
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.
Or simply open the web UI of traefik in you preferred browser. On the top left corner is the actual used version stated.
Theres alway the simple way or the overcomplicated
It is pretty hard to open the UI of traefik when you don’t have it. The topic was about finding the version in general. Also anything you see on a webinterface is probably the version of the application which is not necessarily the version of the image. Let’s say you use Application v1.3.4, but there was a bug in the process of building the image. There will be a newer image but not a newer application. I can’t say I saw it often, but could happen. If the app was built for Docker container at its core, the image version and the app version could change together, but otherwise these could be independent versions so finding a newer ersion of the image could be complicated unless you have a tool that just tells you the answer using the registry API and the local image info. In applications that shows you on the webinterface when a newer app version is released, you can indeed learned about the new App version, but sometimes it is posisble that the image is not built yet. It all depends on the exact app.
A point I’ve just ignored right! A very rare situation, but yes, possible.