最佳答案
我正在为 Darshan 公司编写一个多级 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,这样我就可以只定义一次默认的构建变量。 如果我在两个阶段都重复 ARG,就在两个 FROM 之下,它会正确构建。
定义默认的“全局”多级 ARG 变量的正确方法是什么?