Share variable in multi-stage Dockerfile: ARG before FROM not substituted

ARGs only last for the build phase of a single image.
For the multistage, renew the ARG by simply stating:

ARG DARSHAN_VER

after your FROM instructions.

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}"
...

Leave a Comment