如何在 Docker 中创建命名和最新标签?
假设我有一个图像想要标记为 0.10.24
(在我的例子中它是一个包含 Node.js 0.10.24 的图像).我使用 Dockerfile 并执行 docker build
并通过使用 -t
参数提供标签来构建该映像.
Supposed I have an image that I want to tag as 0.10.24
(in my case it's an image containing Node.js 0.10.24). I built that image using a Dockerfile and executing docker build
and by providing a tag using the -t
parameter.
我希望有一天我会有该图像的其他版本,因此我将重新运行该过程,只是使用另一个标签名称.
I expect that one day I will have additional versions of that image, so I will rerun the process, just with another tag name.
到目前为止,一切都很好.这很好用,一切都很好.
So far, so good. This works great and fine and all is well.
但是,这就是问题开始的地方,我还希望始终将最新的图像标记为 latest
附加广告.所以我想我需要给同一个图像取两个名字.
But, and this is where problems start, I also want to always have the newest image tagged ad latest
additionally. So I guess I need to give two names to the very same image.
我该怎么做?我真的需要再次在完全相同的版本上重新运行 docker build
,但这次使用另一个标签,有没有更好的选择?
How do I do this? Do I really need to re-run docker build
on the exact same version again, but this time use another tag, is is there a better option?
构建镜像时可以有多个标签:
You can have multiple tags when building the image:
$ docker build -t whenry/fedora-jboss:latest -t whenry/fedora-jboss:v2.1 .
参考:https://docs.docker.com/engine/reference/命令行/构建/#tag-image-t