title: How to make environmental variables available to Docker RUN commands from docker-compose?
body: <p>I have a Dockerised application which I would like to run in both proxy and non-proxy host environments. I'm trying to resolve this problem by copying the normal environment variables, such as http_proxy, into the containers if and only if they exist in the host. </p>
  
  <p>I can get 90% of the way there by running </p>
  
  <pre><code>set | grep -i _proxy=&gt;proxies.env
  </code></pre>
  
  <p>in a top-level script, and then having, in my docker-compose.yml:</p>
  
  <pre><code>myserver:
    build: ./myserver
    env_file:
     - proxies.env
  </code></pre>
  
  <p>This copies the host's environmental proxy variables, if any, into the server container, and it works in the sense that these variables are available at container run time, in other words by the stage that the Dockerfile CMD or ENTRYPOINT executes.</p>
  
  <p>However I have one container which needs to run npm as a build step, ie from a RUN command in the Dockerfile, and these variables appear not to be present at this stage, so npm can't find the proxy and hangs. In other works, if I have</p>
  
  <pre><code>RUN set
  </code></pre>
  
  <p>in my Dockerfile, I can't see any variables from proxies.env, but if I do</p>
  
  <pre><code>docker exec -it myserver /bin/bash
  </code></pre>
  
  <p>and then run set, I can see everything from proxies.env.</p>
  
  <p>Can anyone recommend a way to make these variables visible at container build time, without having to hard-code them, so that my docker-compose.yml and Dockerfile will still work both for hosts with proxies and hosts without proxies?</p>
  
  <p>(Running with centos 7, docker-compose 1.3.1 and docker 1.7.0)</p>