Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make a Docker hub use the same image for "latest" and "vX.Y"?

Docker Hub builds a Syncthing image for me from this source repo.

I tagged the latest commit v0.13.5, but Docker built it twice: once for latest and once for v0.13.5.

Why? Shouldn't it be able to figure out the source is the same? Am I just doing something dumb in my Dockerfile, breaking caching? Is there some way I need to hint to Docker Hub that this should really be two images with the same checksum but different tags?

I'm thinking of the two Docker image tags latest and v0.13.5 like two git tags both pointing to the same commit. Shouldn't Docker Hub work that way too? If someone tries to pull latest they'd pull exactly the same image tagged v0.13.5? I know how to pull/re-tag/push, but again, seems like there just must be some way to get Docker Hub to do this automatically.

Build settings:

screenshot of meonkeys/syncthing build settings

like image 893
Adam Monsen Avatar asked Jun 06 '16 05:06

Adam Monsen


People also ask

How do I push updated image to Docker Hub?

To push an image to Docker Hub, you must first name your local image using your Docker Hub username and the repository name that you created through Docker Hub on the web. You can add multiple images to a repository by adding a specific :<tag> to them (for example docs/base:testing ).

Does docker always pull the latest image?

docker pull will always contact the registry and get an updated image. Try, for instance, docker pull ubuntu:18.04 if you have it locally and haven't pulled it recently.


2 Answers

With a little magic, Docker Hub can do this! Pablo Chico de Guzmán helped me out.

Steps:

  1. add a file called hooks/post_push
  2. make hooks/post_push executable, commit and push
  3. delete the "Branch" build, but leave the "Tag" build in place

Now, any tags I push (e.g. git push --tags) fire off an automated build, and the same image is also given the latest tag.

Here's the change I had to make so the most recent "vX.Y"-tagged meonkeys/syncthing image is also tagged latest.

screenshot of Docker Hub build settings for my syncthing image

like image 136
Adam Monsen Avatar answered Oct 31 '22 20:10

Adam Monsen


Latest is just “the last build/tag that ran without a specific tag/version specified”.

If you push a tagged image it does not replace the current image tagged with latest. If you push tagged images only, latest tag is not added.

Automated Builds on Docker Hub is adding the latest tag automatically for the master branch.

like image 35
molivier Avatar answered Oct 31 '22 19:10

molivier