如何在Dockerfile中设置图像名称? [英] How to set image name in Dockerfile?
问题描述
您可以在构建自定义图像时设置图像名称,如下所示:
You can set image name when building a custom image, like this:
docker build -t dude/man:v2 . # Will be named dude/man:v2
有没有办法定义图像的名称Dockerfile,所以我不必在 docker build
命令中提到它。
Is there a way to define the name of the image in Dockerfile, so I don't have to mention it in the docker build
command?
推荐答案
Dockerfile中不支持标记图像。这需要在你的构建命令中完成。作为解决方法,您可以使用docker-compose.yml进行构建,该docker-compose.yml标识目标映像名称,然后运行 docker-compose build
。一个示例docker-compose.yml看起来像
Tagging of the image isn't supported inside the Dockerfile. This needs to be done in your build command. As a workaround, you can do the build with a docker-compose.yml that identifies the target image name and then run a docker-compose build
. A sample docker-compose.yml would look like
version: '2'
services:
man:
build: .
image: dude/man:v2
这篇关于如何在Dockerfile中设置图像名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!