title: Sending SSH key into docker using env variables not working
body: <p>Am trying to install some private gems(bitbucket git repo) in my docker file and the SSH permission is being denied</p>
  
  <p>What I did was:</p>
  
  <ol>
  <li>set my private key to "ssh_key" env variable</li>
  <li>set a "ssh_config" env variable as "IdentityFile /.ssh/id_rsa Host  User "</li>
  <li>In docker-compose: </li>
  </ol>
  
  <pre><code>    args:
              ssh_key: ${ssh_key}
              ssh_config: ${ssh_config}
  
  </code></pre>
  
  <ol start="4">
  <li>In Dockerfile:</li>
  </ol>
  
  <pre><code>    ARG ssh_key
      ARG ssh_config
      RUN mkdir /.sshRUN echo "${ssh_key}" &gt; /.ssh/id_rsa
      RUN echo "${ssh_config}" &gt; /etc/ssh/ssh_config
      RUN chmod 600 /.ssh/id_rsa
      bundle install
  </code></pre>
  
  <p>I get the error</p>
  
  <pre><code>fatal: Could not read from remote repository.
  
  Please make sure you have the correct access rights
  and the repository exists.
  </code></pre>
  
  <p>But when I comment out the private gems and build the image, ssh into the container, remove the id_rsa file and manually paste the host private key using a text editor and run chmod 600(or just mount my host ~/.ssh dir ), then am able to install the private gems without any error.</p>
  
  <p>I don't know what's exactly causing the error. Is there any simpler way to achieve this?</p>
  
  <p>Thanks</p>