【发布时间】:2018-08-23 08:57:44
【问题描述】:
我正在尝试使用 Docker 构建多阶段映像,其中我使用外部映像作为阶段。我正在尝试使用 ARG 或 ENV 定义外部图像版本,但它似乎不受支持。
例如。第一个版本,没有参数替换正在工作
Dockerfile
FROM ubuntu:18.04
# This is working
COPY --from=hello-world:latest /hello /hello
Docker 构建
$ 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
虽然带有参数替换的第二个版本不起作用 Dockerfile FROM 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 构建
$ 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 dockerfile