14

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).

Saurabh Shah
  • 576
  • 1
  • 5
  • 19

4 Answers4

13

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?

Community
  • 1
  • 1
tworabbits
  • 1,203
  • 12
  • 17
  • But when i try to pull a image without specifying the tag, I got "Tag latest not found in repository docker.io/landpack/hello". why ? – Frank AK Apr 11 '18 at 09:08
  • 5
    It does not really answer the question "How to pull latest image?" – SerG Oct 11 '19 at 18:15
  • 2
    @SerG - because *there is no way to pull the latest image*. It doesn't work auto-magically. Instead, you have to do something special when *pushing* the image. If you follow the link in the answer, you will see a Q&A with the details. – ToolmakerSteve Nov 03 '19 at 16:33
4

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 :-)

  • 2
    With the huge difference that pushing to a git repo without specifying a tag automatically becomes the master's HEAD; – tworabbits Jul 26 '17 at 04:25
  • 1
    But unlike git, where if you "pull" again from master, you'll receive changes since you last pulled, if you pull "latest" from Docker, and you already have "latest", then nothing changes. – ProgrammingLlama Sep 19 '17 at 05:09
3

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.

Saurabh Shah
  • 576
  • 1
  • 5
  • 19
  • 1
    This fails for tags going above `99` e.g. `1, 2, ... 100, ...`. A stabler solution would be: `| jq -r '[.[] | {tag: (.name)|tonumber}.tag] | sort | .[-1]'`. Also, make sure you don't lose any `.0` suffix when parsing with `tonumber`, if that's the case append it at the end. – reim May 10 '22 at 16:21
0

You can also use the below format:

https://github.com/koudaiii/qucli/issues/47#issuecomment-503066074

Ömer An
  • 600
  • 5
  • 16