title: git clone project using a env variable
body: <p>I have a Dockerfile that git clones a project like this:</p>
  
  <pre><code>...
  RUN git clone -b 027-infra http://201.57.129.38/arbitrium/api.git
  ...
  </code></pre>
  
  <p>I want to replace the <code>027-infra</code> (the desired branch of the project) with an environment variable, but according to the docs <a href="https://docs.docker.com/engine/reference/builder/#environment-replacement" rel="nofollow noreferrer">https://docs.docker.com/engine/reference/builder/#environment-replacement</a> seems the RUN instruction doesn't support env variables. Have no idea why!</p>
  
  <p>How can I git clone the project using an external variable to choose the branch?</p>
  
  <p>Some other info:</p>
  
  <ul>
  <li>Repository is public and open-source. No problems with ssh keys or whatever.</li>
  <li>I use a docker-compose with 3 services, 2 of them git clone 2 different repositories. In the end I would like to use a single variable, so both services checkout the same branch name, but on different repositories. That's why I can't use COPY, because that would only have the context for the first repository.</li>
  </ul>
  
  <hr>
  
  <p>Update:</p>
  
  <p>Couldn't get env variables working, but I did with args. Seems like I needed to add a ARG call to accept the argument during container build:</p>
  
  <pre><code>...
  ARG GIT_BRANCH
  RUN git clone -b ${GIT_BRANCH} http://201.57.129.38/arbitrium/web.git
  ...
  </code></pre>
  
  <p>and call the build either with a <code>docker-compose build</code>, or like these <code>docker build --build-arg GIT_BRANCH=027-infra -t arbitrium_api:latest -f Dockerfile_api .</code></p>
  
  <p>Still don't understand why env variables doesn't seem to be replaced in the git clone run.</p>