How to export environment variable to docker image?

I can define "static" environment variables in a Docker file with ENV , but is it possible to pass some value during the assembly of this variable? I am trying something like this that doesn't work:

 FROM phusion/baseimage RUN mkdir -p /foo/2016/bin && \ FOOPATH=`ls -d /foo/20*/bin` && \ export FOOPATH ENV PATH $PATH:$FOOPATH 

Of course, in the real case, I will run / unzip something that creates a directory whose name will change with different versions, dates, etc., and I would like to avoid modifying the Docker file every time the directory changes its name.


Edit: since this seems impossible, the best workaround so far is to use a symbolic link:

 FROM phusion/baseimage RUN mkdir -p /foo/2016/bin && \ FOOPATH=`ls -d /foo/20*/bin` && \ ln -s $FOOPATH /mypath ENV PATH $PATH:/mypath 
+5
source share
1 answer

To pass a value during assembly, use ARG .

 FROM phusion/baseimage RUN mkdir -p /foo/2016/bin && \ FOOPATH=`ls -d /foo/20*/bin` && \ export FOOPATH ARG FOOPATH ENV PATH $PATH:${FOOPATH} 

Then you can run docker build --build-arg FOOPATH=/dir -t myimage .


Edit: from your comment, my answer above will not solve your problem. Nothing in the Dockerfile that you can update from the output of the run command, the output is not analyzed, only the resulting file system is saved. For this, I think that it’s best for you to enter the path to the image in the start command and read it from your / etc / profile or user script entry point. It depends on how you want to run your container and base image.

+5
source

Source: https://habr.com/ru/post/1261847/


All Articles