作者:爷们疯子2_593_278 | 来源:互联网 | 2022-11-26 06:34
我正在为darshan utils写一个多阶段的Dockerfile :
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}"
...
我建立它,docker build -t darshan-util:3.6.1 .
我得到的错误是:
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,以便可以只定义一次默认的构建变量。如果在两个阶段中都在两个FROM的正下方复制ARG,它将正确构建。
用默认值定义“全局”多阶段ARG变量的正确方法是什么?
1> Richard Barb..:
ARG仅在单个映像的构建阶段持续。对于多阶段,只需说明以下内容即可更新ARG:
ARG DARSHAN_VER
在您的FROM指令之后。
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}"
...