Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

define a locale environment variable in Dockerfile

Is there any way to create local variables in Dockerfile that only available during the build process? What I can see is if I define a variable with the ENV keyword, then it will be available later in the image as an exported environment variable. But I would like to have a "technical" variable with build scope only.

I would like to avoid repetition in my Doclerfile so I would like to have a variable available only from the Dockerfile:

ENV MY_JAR=myJar.jar
COPY bin/$MY_JAR $ORACLE_HOME/user_projects/domains/$DOMAIN_NAME/lib/
COPY bin/$MY_JAR $ORACLE_HOME/wlserver/server/lib/mbeantypes/

But the MY_JAR variable appears in the container. I do not need it there. It just confuses users. Can I do this somehow?

like image 682
zappee Avatar asked Mar 25 '26 15:03

zappee


1 Answers

Use ARG instead of ENV

ARG MY_JAR=myJar.jar  # ARG is only available during the build of a Docker image
COPY bin/$MY_JAR $ORACLE_HOME/user_projects/domains/$DOMAIN_NAME/lib/
COPY bin/$MY_JAR $ORACLE_HOME/wlserver/server/lib/mbeantypes/

see also ARG or ENV, which one to use in this case?

like image 92
frank_lee Avatar answered Mar 28 '26 02:03

frank_lee