title: Passing in environment variables into docker file that is build via a compose yaml
body: <p>I am calling a docker file thru my docker compose file by running command docker-compose build. I have my environment variables defined in a .env file. When I do the build, in my docker file, everything works except this line</p>
  
  <pre><code>RUN git config --global user.email ${USER_NAME}
  </code></pre>
  
  <p>It fails with the message</p>
  
  <pre><code>←[31mERROR←[0m: Service 'git' failed to build: The command '/bin/sh -c git confi
  g --global user.email ${USER_NAME}' returned a non-zero code: 1
  </code></pre>
  
  <p>However if I echo ${USER_NAME} during container load (docker-compose up) it is able to print out that variable correctly.</p>
  
  <pre><code>ENTRYPOINT  echo ${USER_NAME}//this works
  </code></pre>
  
  <p><strong>What is the right way to pass in an environment variable in a run command in the docker file?</strong></p>
  
  <p>Update: Here is a stripped down version of the files</p>
  
  <p>yaml file</p>
  
  <pre><code>version: '2'
  services:
      git:
          build:
            context: ./git
            args:
              - USER_NAME
          env_file:
           - ./common.env
  </code></pre>
  
  <p>Env file</p>
  
  <pre><code>USER_NAME="My test user"
  </code></pre>
  
  <p>Docker file:</p>
  
  <pre><code>FROM xxx
  
  ARG USER_NAME 
  
  RUN git config --global user.name ${USER_NAME} 
  ENTRYPOINT git config --list
  </code></pre>
  
  <p>Commands
  Build: </p>
  
  <pre><code>docker-compose build git
  </code></pre>
  
  <p>Run:</p>
  
  <pre><code>docker-compose up git
  </code></pre>
  
  <p>The build fails with the error</p>
  
  <pre><code>RUN git config --global user.name ${USER_NAME}
   ---&gt; Running in 7b67ddeae989
  ←[31mERROR←[0m: Service 'git' failed to build: The command '/bin/sh -c git config --global user.name ${USER_NAME}' returned a non-zero code: 1
  </code></pre>