无法让Docker扩展文件头的ARG定义 [英] Can't get Docker to expand ARG define at head of file
问题描述
我有一个基于Windows 10的Dockerfile,我想与柯南一起使用.我的问题是我无法让Docker扩展我在文件开头定义的ARG.在此示例中:
I have a Dockerfile that is based on Windows 10 that I want to use with conan. My problem is that I cannot get Docker to expand an ARG I defined at the head of the file. In this sample:
ARG conan_repository=https://feeds.genetec.com/artifactory/api/conan/conan
ARG conan_remote=genetec
FROM mcr.microsoft.com/windows:1903
RUN conan remote add ${conan_remote ${conan_repository}
或
RUN conan remote add $conan_remote $conan_repository
总是以
C:\>conan remote list
conan-center: https://conan.bintray.com [Verify SSL: True]
$conan_remote: $conan_repository [Verify SSL: True]
在我连接到图像后手动添加柯南遥控器效果很好.
Adding the conan remote manually after I connected to the image works well.
我看不到在文档中找到与此有关的任何内容吗?
I can't seen to find anything on the docs about this?
推荐答案
将 ARG
行移到 FROM
行之后.
在Dockerfile参考中,请参见了解ARG和FROM之间的交互方式.特别是:
In the Dockerfile reference, see Understand how ARG and FROM interact. In particular:
在
FROM
之前声明的ARG
在构建阶段之外,因此不能在FROM
之后的任何指令中使用它
An
ARG
declared before aFROM
is outside of a build stage, so it can’t be used in any instruction after aFROM
.
您可以使用 ARG
来控制要从哪个图像开始(例如为基础图像选择特定的标签),在这种情况下,必须先使用 ARG
.否则,您需要将 ARG
放在 FROM
之后,并且如果在多阶段Dockerfile的多个部分中使用了相同的 ARG
,则需要在每个阶段重复一次.
You can use ARG
to control which image you’re starting from (like picking a specific tag for the base image), in which case ARG
has to come first. Otherwise, you need to put ARG
after FROM
, and if the same ARG
is used in multiple parts of a multi-stage Dockerfile, you need to repeat it for each stage.
这篇关于无法让Docker扩展文件头的ARG定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!