当前位置: 首页 > 知识库问答 >
问题:

无法在复制指令中使用ARG构建Docker多级映像

刘胜泫
2023-03-14
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
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/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

你已经经历过了吗?干杯,奥利维尔

共有1个答案

邢炯
2023-03-14

好吧。我发现这是Docker方面的一个悬而未决的问题。https://github.com/moby/moby/issues/35018

-->arg/env替换对addcopy中的--值无效。

对于我的情况,在Docker中等待更正时有一个工作。https://github.com/docker/cli/issues/996

ARG HELLO_VERSION
FROM hello-world:${HELLO_VERSION:-latest} as hello

FROM ubuntu:18.04
COPY --from=hello /hello /hello
 类似资料:
  • 我正在尝试使用docker buildx构建一个多平台(amd64、arm64和armv7)映像。因为我使用的是运行Ubuntu 18.04的amd64机器,所以我按照Docker网站上的说明,通过以下方式安装了qemu: 但是,当我执行前面的命令时,会出现一个奇怪的错误。更具体地说,binfmt-support服务似乎有问题。以下是完整的日志: 尽管如此,我还是试着按照通常的程序进行,即: 其中

  • 我有一个简单的Dockerfile来将python需求构建到一个zip文件中,然后上传到AWS Lambda。 有没有复制python的方法。在dockerfile期间将图像压缩到主机?

  • 我想在我的Ubuntu上运行我的 Scrape.py Docker。我的步骤: 我使用 我创建了一个Docker文件: 请问有什么问题?谢谢

  • 问题内容: 我有一个Dockerfile,其中在指令中使用了: arg通过docker-compose传递: 但是,似乎并未针对展开。我之后。 这是检查显示的内容: 问题答案: 问题是只能在构建时使用,而在运行时正在执行。我想现在唯一实现您想要的方法是在Dockerfile中使用该值设置环境变量。

  • 问题内容: 我尝试在构建映像的同时使用Docker安装软件,然后得到了。 我使用的Dockerfile 有没有一种方法可以在Dockerfile中运行docker命令来创建映像? 问题答案: 您的问题不在于Docker命令,因为它在错误消息中表示您的Docker守护程序未运行,或者由于某些配置问题而无法连接到它。 您刚刚安装了Docker吗?您是否完成了《安装指南》中的所有步骤? 您可以使用或来测

  • @Component({ selector: 'app-root', template: ` <div class="tabs-selection"> <tab *ngFor="let tab of tabs; let i = index" [active]="isSelected(i)" (click)="setTab(