What is the best way to reference a FROM as a variable in a RUN statement? Thank you :).
FROM alpine:3.12.5
RUN ...... \
...... \
echo on `date` $FROM was used > log
contents of log
on 2/2/2022 alpine:3.12.5 was used
Share and learn in the Docker community.
What is the best way to reference a FROM as a variable in a RUN statement? Thank you :).
FROM alpine:3.12.5
RUN ...... \
...... \
echo on `date` $FROM was used > log
contents of log
on 2/2/2022 alpine:3.12.5 was used
I am afraid itās not going to work like that, but you could declare an ARG with for the base image:
ARG BASE_IMAGE=alpine:3.12.5
FROM ${BASE_IMAGE}
RUN echo "on $(date) ${BASE_IMAGE} was used"
That should do the trick
Thank you very much :).
That would not work this way, but it is almost right. You canāt use a build argument in a stage which was only defined outside of any stage. So you have to define it this way:
ARG BASE_IMAGE=alpine:3.12.5
FROM ${BASE_IMAGE}
ARG BASE_IMAGE
RUN echo "on $(date) ${BASE_IMAGE} was used"
The second declaration does not need a value
Good catch Indeed I forget that it behaves like that