Is there any way to use the arguments defined in the parent docker image?
Given the following child Dockerfile
FROM jenkins
USER ${user}
RUN echo "${user}"
Excerpt from parent Dockerfile
FROM openjdk:8-jdk
ARG user=jenkins
ARG group=jenkins
ARG uid=1000
ARG gid=1000
Build arguments are not persisted in images, so they will not be available in builds FROM
a parent image.
Unlike an ARG instruction, ENV values are always persisted in the built image.
ARG variables are not persisted into the built image as ENV variables are.
The arguments can be persisted by storing them somewhere, the easiest place is in an environment variable.
ARG IMAGE_USER=jenkins
ENV IMAGE_USER=$IMAGE_USER
All RUN
steps in the child image will then have access to IMAGE_USER
in their environment.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With