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

核能气质少年 提交于 2019-12-07 13:31:00

问题


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:


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/37650119/how-do-i-make-a-docker-hub-use-the-same-image-for-latest-and-vx-y

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!