如何在Docker文件中定义一个变量? [英] How to define a variable in a Dockerfile?
问题描述
在我的 Dockerfile 中,我希望定义变量,以后可以在Dockerfile 中使用
In my Dockerfile, I would like to define variables that I can use later in the Dockerfile.
我知道 ENV
指令,但我不希望这些变量作为环境变量。
I am aware of the ENV
instruction, but I do no want these variables to be environment variables.
有没有办法在Dockerfile范围中声明变量?
Is there a way to declare variables at Dockerfile scope?
推荐答案
您可以使用 ARG
- 请参阅 https://docs.docker.com/engine/reference/builder/#arg
You can use ARG
- see https://docs.docker.com/engine/reference/builder/#arg
ARG
指令定义一个变量,用户可以通过
生成时间向构建器传递docker build
命令使用
- build-arg< varname> =< value>
标志。如果用户指定了在Docker文件中未定义的build
参数,则构建会输出
错误。
The
ARG
instruction defines a variable that users can pass at build-time to the builder with thedocker build
command using the--build-arg <varname>=<value>
flag. If a user specifies a build argument that was not defined in the Dockerfile, the build outputs an error.
这篇关于如何在Docker文件中定义一个变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!