Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass arguments to parent Dockerfile

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
like image 650
Christian Gripp Avatar asked Dec 11 '16 16:12

Christian Gripp


1 Answers

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.

like image 180
Matt Avatar answered Nov 17 '22 06:11

Matt