多阶段Dockerfile:FROM之前的ARG未替换 [英] Multi-stage Dockerfile: ARG before FROM not substituted
问题描述
我正在为 darshan utils 编写多阶段Dockerfile。 :
I'm writing a multi-stage Dockerfile for the darshan utils:
ARG DARSHAN_VER=3.1.6
FROM fedora:29 as build
RUN dnf install -y \
gcc \
make \
bzip2 bzip2-devel zlib zlib-devel
RUN curl -O "ftp://ftp.mcs.anl.gov/pub/darshan/releases/darshan-${DARSHAN_VER}.tar.gz" \
&& tar ...
FROM fedora:29
COPY --from=build "/usr/local/darshan-${DARSHAN_VER}" "/usr/local/darshan-${DARSHAN_VER}"
...
我用<$ c $构建它c> docker build -t darshan-util:3.6.1。而我得到的错误是:
I build it with docker build -t darshan-util:3.6.1 .
and the error I get is:
Step 5/10 : RUN curl -O "ftp://ftp.mcs.anl.gov/pub/darshan/releases/darshan-${DARSHAN_VER}.tar.gz" && tar ...
---> Running in 9943cce1669c
% Total % Received % Xferd Average Speed Time Time Time Current
...
curl: (78) RETR response: 550
The command '/bin/sh -c curl -O "ftp://ftp.mcs.anl.gov/pub/darshan/releases/darshan-${DARSHAN_VER}.tar.gz" && tar ...' returned a non-zero code: 78
我想重复使用相同的代码这两个阶段都使用ARG,因此我只能定义一次默认的构建变量。
如果我在两个阶段中都复制了ARG,在两个FROM的正下方,它将正确构建。
I'd like to reuse the same ARG in both stages, so that I can define a default build variable just once. If I duplicate ARG in both stages, just below the two FROMs, it builds correctly.
定义全局多目标代码的正确方法是什么
What is the correct way to define a "global" multi-stage ARG variable with a default?
推荐答案
ARG仅在单个图像的构建阶段有效。
对于多阶段,只需说明以下内容即可更新ARG:
ARGs only last for the build phase of a single image. For the multistage, renew the ARG by simply stating:
ARG DARSHAN_VER
。
cf。 https://docs.docker.com/engine/reference/builder/#arg
ARG DARSHAN_VER=3.1.6
FROM fedora:29 as build
ARG DARSHAN_VER
RUN dnf install -y \
gcc \
make \
bzip2 bzip2-devel zlib zlib-devel
RUN curl -O "ftp://ftp.mcs.anl.gov/pub/darshan/releases/darshan-${DARSHAN_VER}.tar.gz" \
&& tar ...
FROM fedora:29
ARG DARSHAN_VER
COPY --from=build "/usr/local/darshan-${DARSHAN_VER}" "/usr/local/darshan-${DARSHAN_VER}"
...
这篇关于多阶段Dockerfile:FROM之前的ARG未替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!