gpt4 book ai didi

docker - 管理Docker Hub镜像版本的正确方法

转载 作者:行者123 更新时间:2023-12-02 18:15:06 43 4
gpt4 key购买 nike

理想方案:

我为现有的Docker Hub仓库创建一个新标签:
docker build . -t org/repo:v1
我有一个docker-compose读取该标签:

version: '2'
services:
api:
image: org/repo
...

但是,这没有用,因为没有最新标签。

有没有办法得到这种行为?否则,每个部署都必须修改看上去很愚蠢的 docker-compose.yml

我有一个丑陋的解决方案,但它可行:
我只需要重新标记并推送最新标记即可。
docker tag org/repo:v1 org/repo:latest
docker push org/repo:latest

还有更好的主意吗?

最佳答案

请参阅The misunderstood Docker tag: latest 中的“Marc Campbell”:latest是引用已推送标签的标签:

Latest is just a tag with a special name.

It doesn’t mean anything special unless you use a pretty specific build/tag/push/pull/run pattern.

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

In other words, you could build new versions like this:

sudo docker build -t marc/test .
sudo docker tag marc/test marc/test:2
...
sudo docker build -t marc/test .
sudo docker tag marc/test:3
...

But this is a little odd. Why would I have to tag everything twice?

If you are shipping Docker images to a production environment, you should just ignore the latest tag.
Don’t use it. Don’t be tempted by it.
It’s easy to look at it and think that your deployment script should just pull “latest” and your build process will ensure that’s valid. It takes a lot of discipline to make that work. Just version your tags. Every time.



Docker: The latest Confusion 中查看更多带有“ Adrian Mouat”的内容:

If the repository is to be uploaded to the Docker Hub, the repository name must be prefixed with a slash and the Docker Hub user name e.g. amouat/myrepo:mytag.

The trick is of course, if you leave the tag part out (e.g. docker tag myrepo:1.0 myrepo), Docker will automatically give it the tag latest.



参见“ How to create named and latest tag in Docker?”。

Just because an image is tagged latest, does not mean that it is the most up-to-date image within its repository.

So what happens if you do the pull on a repository with no latest tag?
This:

$ docker pull amouat/myrepo
Pulling repository amouat/myrepo
2015/01/21 12:04:06 Tag latest not found in repository amouat/myrepo


OP添加:

The issue I had is trying to keep the dev environment synced with latest changes without having to manually edit the docker-compose.yml with the new tag every change.



为此,我总是维护一个“正在部署”的标签,该标签正在转移(仅在升级图像标签时才应用),并在scripts / docker-compose.yml中使用。

我更喜欢为 add LABEL s构建自己的镜像,该镜像用于存储“已部署”标签的实际含义(我在其中设置了一个名为“tag”的LABEL,其中包含实际的标签名称)。

关于docker - 管理Docker Hub镜像版本的正确方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50429726/

43 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com