title: How to export an environment variable to a docker image?
body: <p>I can define "static" environment variables in a Dockerfile with <code>ENV</code>, but is it possible to pass some value at build time to this variable? I'm attempting something like this, which doesn't work:</p>
  
  <pre><code>FROM phusion/baseimage
  
  RUN mkdir -p /foo/2016/bin &amp;&amp; \
      FOOPATH=`ls -d /foo/20*/bin` &amp;&amp; \
      export FOOPATH
  
  ENV PATH $PATH:$FOOPATH
  </code></pre>
  
  <p>Of course, in the real use case I'd be running/unpacking something that creates a directory whose name will change with different versions, dates, etc., and I'd like to avoid modifying the Dockerfile every time the directory name changes.</p>
  
  <hr>
  
  <p>Edit: Since it appears it's not possible, the best workaround so far is using a symlink:</p>
  
  <pre><code>FROM phusion/baseimage
  
  RUN mkdir -p /foo/2016/bin &amp;&amp; \
      FOOPATH=`ls -d /foo/20*/bin` &amp;&amp; \
      ln -s $FOOPATH /mypath
  
  ENV PATH $PATH:/mypath
  </code></pre>