title: Pass argument to Dockerfile from a file with docker-compose (SSH private key)
body: <p>Hi!</p>
  
  <p>I'm kinda stuck in docker-compose, as I need to pass my private SSH key to my <code>Dockerfile</code> declared in my <code>docker-compose.yml</code>, as below:</p>
  
  <p><strong>docker-compose.yml</strong></p>
  
  <pre><code>version: '3.7'
  services:
    worker:
      build: .
      args:
        - SSH_PRIVATE_KEY
  </code></pre>
  
  <p><strong>Dockerfile</strong></p>
  
  <pre><code>ARG SSH_PRIVATE_KEY
  RUN mkdir /root/.ssh/  &amp;&amp; \
      echo "${SSH_PRIVATE_KEY}" &gt; /root/.ssh/id_rsa &amp;&amp; \
      chmod 600 /root/.ssh/id_rsa
  </code></pre>
  
  <p>With docker itself, that's quite easy, as I just need to run the following command:</p>
  
  <pre><code>docker build . --build-arg SSH_PRIVATE_KEY="$(cat ~/.ssh/id_rsa)"
  </code></pre>
  
  <p>But in docker-compose... The problem of the <code>ARGS</code> configuration in docker-compose as described <a href="https://stackoverflow.com/questions/34322631/how-to-pass-arguments-within-docker-compose">in another question</a> is that I can't let the private key inside the <code>docker-compose.yml</code> file. </p>
  
  <p>I need to let docker-compose access to the key inside <code>~/.ssh/id_rsa</code>: Any clue on how to perform that?</p>
  
  <p>Thank you!</p>