Can';t使用复制指令中的ARG构建Docker多级映像

Can';t使用复制指令中的ARG构建Docker多级映像,docker,dockerfile,Docker,Dockerfile,我试图用Docker构建一个多阶段的图像,在这里我使用一个外部图像作为一个阶段。我正在尝试使用ARG或ENV定义外部映像版本,但它似乎不受支持 第一个版本,没有争论替换正在运行 Dockerfile FROM ubuntu:18.04 # This is working COPY --from=hello-world:latest /hello /hello 码头工人建造 $ docker build --no-cache -t test . Sending build context to

我试图用Docker构建一个多阶段的图像,在这里我使用一个外部图像作为一个阶段。我正在尝试使用ARG或ENV定义外部映像版本,但它似乎不受支持

第一个版本,没有争论替换正在运行

Dockerfile

FROM ubuntu:18.04

# This is working
COPY --from=hello-world:latest /hello /hello
码头工人建造

$ docker build --no-cache -t test .
Sending build context to Docker daemon  2.048kB
Step 1/2 : FROM ubuntu:18.04
 ---> 16508e5c265d
Step 2/2 : COPY --from=hello-world:latest /hello /hello
 ---> 2d52b43d730b
Successfully built 2d52b43d730b
Successfully tagged test:latest
$ docker build --no-cache -t test .
Sending build context to Docker daemon  2.048kB
Step 1/5 : FROM ubuntu:18.04
 ---> 16508e5c265d
Step 2/5 : ARG HELLO_VERSION
 ---> Running in bf1c94ecd0ea
Removing intermediate container bf1c94ecd0ea
 ---> 33608ed5d441
Step 3/5 : ENV HELLO_VERSION ${HELLO_VERSION:-latest}
 ---> Running in 6bf864ba9e4f
Removing intermediate container 6bf864ba9e4f
 ---> d08f20e7ccb6
Step 4/5 : RUN echo "HELLO_VERSION" $HELLO_VERSION
 ---> Running in cd973f372eb4
HELLO_VERSION latest
Removing intermediate container cd973f372eb4
 ---> b0893a822140
Step 5/5 : COPY --from=hello-world:${HELLO_VERSION} /hello /hello
invalid from flag value hello-world:${HELLO_VERSION}: invalid reference format
而带有参数替换的第二个版本不起作用 Dockerfile 来自ubuntu:18.04

ARG HELLO_VERSION
ENV HELLO_VERSION ${HELLO_VERSION:-latest}

RUN echo "HELLO_VERSION" $HELLO_VERSION
# This argument substitution is NOT working --I tried both ARG and ENV separately
COPY --from=hello-world:${HELLO_VERSION} /hello /hello
码头工人建造

$ docker build --no-cache -t test .
Sending build context to Docker daemon  2.048kB
Step 1/2 : FROM ubuntu:18.04
 ---> 16508e5c265d
Step 2/2 : COPY --from=hello-world:latest /hello /hello
 ---> 2d52b43d730b
Successfully built 2d52b43d730b
Successfully tagged test:latest
$ docker build --no-cache -t test .
Sending build context to Docker daemon  2.048kB
Step 1/5 : FROM ubuntu:18.04
 ---> 16508e5c265d
Step 2/5 : ARG HELLO_VERSION
 ---> Running in bf1c94ecd0ea
Removing intermediate container bf1c94ecd0ea
 ---> 33608ed5d441
Step 3/5 : ENV HELLO_VERSION ${HELLO_VERSION:-latest}
 ---> Running in 6bf864ba9e4f
Removing intermediate container 6bf864ba9e4f
 ---> d08f20e7ccb6
Step 4/5 : RUN echo "HELLO_VERSION" $HELLO_VERSION
 ---> Running in cd973f372eb4
HELLO_VERSION latest
Removing intermediate container cd973f372eb4
 ---> b0893a822140
Step 5/5 : COPY --from=hello-world:${HELLO_VERSION} /hello /hello
invalid from flag value hello-world:${HELLO_VERSION}: invalid reference format
你已经经历过了吗? 干杯
奥利维尔

好的。我发现这在Docker方面是一个悬而未决的问题。

-->
ARG
/
ENV
替换不适用于
--
添加
复制
中的值

就我的情况而言,在Docker中有一个等待更正的变通方法。