简体   繁体   English

在Dockerfile中命名映像有什么用

[英]What is use of naming an image in Dockerfile

In a docker file what are the uses of naming an image like so... 在docker文件中,像这样命名图像有什么用...

FROM <image> [AS <name>]

One of uses I found from the docs is - 我从文档中发现的一种用途是-


 - Optionally a name can be given to a new build stage by adding 
AS name to the FROM instruction. The name can be used in subsequent
FROM and COPY --from=<name|index> instructions to refer to the image 
built in this stage.

Are there any other uses? 还有其他用途吗?

One example here which is straight forward - https://medium.com/thepeaklab/how-to-deploy-a-react-application-to-production-with-docker-multi-stage-builds-4da347f2d681 一个简单的例子-https: //medium.com/thepeaklab/how-to-deploy-a-react-application-to-production-with-docker-multi-stage-builds-4da347f2d681

The name/alias is just a way to refer to a specific stage in another stage. 名称/别名只是在另一个阶段中引用特定阶段的一种方式。 So if you are using the normal build no need to use it. 因此,如果您使用的是普通版本,则无需使用它。 Otherwise you will be using the index number for example: 否则,您将使用索引号,例如:

FROM <image_image>
RUN <do_something>
...

FROM <image_name>
COPY --from=0 <files_to_copy> <destination>
...

The name also can be used in conjunction with --target option to the build command for example: 该名称还可以与build命令的 --target 选项结合使用,例如:

FROM debian AS build-env
...

FROM alpine AS production-env
...
$ docker build -t mybuildimage --target build-env .

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM