Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pulling the latest image from dockerhub

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

like image 824
Saurabh Shah Avatar asked Jun 01 '16 10:06

Saurabh Shah


Video Answer


3 Answers

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?

like image 111
tworabbits Avatar answered Oct 26 '22 07:10

tworabbits


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

like image 43
Quentin Stafford-Fraser Avatar answered Oct 26 '22 06:10

Quentin Stafford-Fraser


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.

like image 40
Saurabh Shah Avatar answered Oct 26 '22 07:10

Saurabh Shah