Suppose there is a user repository on dockerhub which has 3 images. Images are tagged as A
, B
and C
. Here C
is my latest tag.
Now I don't know these tags. When I do a docker pull user/image
, this gives me an error saying that Tag latest not found in repository docker.io/user/image
. How can I pull the image with the latest tag(C
in this case).
Yes, I absolutely agree: the latest tag is confusing. The latest tag actually does not necessarily point to the latest version of your image. Let's have a look:
1) When you pull an image without specifying a tag name, Docker will try to pull the image tagged 'latest'
2) When you do not tag an image before your push operation to the registry, Docker will give it the 'latest' tag automatically
3) When you do tag your image and it sounds like that is what you are doing, Docker will never tag anything with 'latest'; You then have to apply the 'latest' tag manually
From my point the 'latest' tag should be a 'default' tag instead and understood as the default image that is pulled from the registry, when no tag name was specified in the pull command.
Refer to this answer for more information on how to apply multiple tags: How to create named and latest tag in Docker?
One way to think of the 'latest' tag is like the 'master' tag in git. In fact, I wish they'd called it that!
If you clone a git repo without specifying a branch, you will get the 'master' branch, even though updates may have been pushed on other branches more recently.
If you pull a Docker image you'll get the 'latest' tag, even though other images may have been pushed on other tags more recently :-)
I think I got the answer to my question :
curl -s -S "https://registry.hub.docker.com/v2/repositories/repo/image/tags/" | jq '."results"[]["name"]'
will give me the list of all the tags in the dockerhub repository. I can then easily pipe this with sed -n 1p
to get the latest commit.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With