title: How to access GIT repo with my private key from Dockerfile
body: <p>I am trying to add a private key in my Docker container which has access to my private git repositories. The testing_git file is in the folder containing Dockerfile. I am trying to make a container which can pull git code on the fly.</p>
  
  <p>This is my Dockerfile:</p>
  
  <pre><code>FROM ubuntu:14.04.1
  WORKDIR ~/.ssh
  RUN apt-get -y install ssh
  WORKDIR /var/www/html
  Run apt-get -y install git
  RUN mkdir ~/.ssh
  ADD id_rsa /home/id_rsa
  RUN cat /home/id_rsa &amp;&amp; mv /home/id_rsa ~/.ssh/id_rsa &amp;&amp; chmod 600 ~/.ssh/id_rsa &amp;&amp; eval "$(ssh-agent -s)"  &amp;&amp; ssh-add ~/.ssh/id_rsa &amp;&amp; ssh-add -l &amp;&amp; ssh-add -L &amp;&amp; echo "Host github.com\n\tIdentityFile ~/.ssh/id_rsa" &gt;&gt; /root/.ssh/config &amp;&amp;  git clone git@github.com:amitbadheka/Learning-Rails
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>Step 9 : RUN mkdir ~/.ssh
  ---&gt; Using cache
  ---&gt; 38f2824f41d6
  Step 10 : ADD id_rsa /home/id_rsa
  ---&gt; Using cache
  ---&gt; afae372c6a40
  Step 11 : RUN cat /home/id_rsa &amp;&amp; mv /home/id_rsa ~/.ssh/id_rsa &amp;&amp; chmod 600 ~/.ssh/id_rsa &amp;&amp; eval "$(ssh-agent -s)"  &amp;&amp; ssh-add ~/.ssh/id_rsa &amp;&amp; ssh-add -l &amp;&amp; ssh-add -L &amp;&amp; echo "Host github.com\n\tIdentityFile ~/.ssh/id_rsa" &gt;&gt; /root/.ssh/config &amp;&amp;  git clone git@github.com:amitbadheka/Learning-Rails.git
  ---&gt; Running in edd6778a0ae6
  -----BEGIN RSA PRIVATE KEY-----
  MY PRIVATE KEY
  -----END RSA PRIVATE KEY-----
  Agent pid 12
  Identity added: /root/.ssh/id_rsa (/root/.ssh/id_rsa)
  2048 69:41:88:d2:5f:22:fa:63:92:2b:f9:b8:a4:1e:3c:24 /root/.ssh/id_rsa (RSA)
  ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCrfPuszAriGJxGd16TVeWBvCt8lj88OlJ0fz5LYd2voWDUDnEmPDpvQUDZKQI+MlFfhPS+KN239XsL4X1+vdyj8xXzcBeUB+DUYW2bxZd0kLsmOPeJ0Htoat12fdjzIC/m+H+j6SkAwL+WrV/vH+tbjNZVrl+zcMvBsZipyrKHmJiwko/cqACRYGRXAAUahnVTfhQGXArqn3ioxNN5r6ZDPdv+xGZY4V9fTbHbDooEHaOz/EFu6xwoBFC2SBID3aKEQgS6C07/iRt1fJ8c8TPPvJt6vLJQ/h5LLsN2WRxDG+V5fCGqWKDdJWoyM+fOuCNOH1XTDka8d+2ZN2v+U1KX /root/.ssh/id_rsa
  Cloning into 'Learning-Rails'...
  **Host key verification failed.**
  **fatal: Could not read from remote repository.**
  Please make sure you have the correct access rights and the repository exists.
  2014/12/15 18:20:47 The command [/bin/sh -c cat /home/id_rsa &amp;&amp; mv /home/id_rsa ~/.ssh/id_rsa &amp;&amp; chmod 600 ~/.ssh/id_rsa &amp;&amp; eval "$(ssh-agent -s)"  &amp;&amp; ssh-add ~/.ssh/id_rsa &amp;&amp; ssh-add -l &amp;&amp; ssh-add -L &amp;&amp; echo "Host github.com\n\tIdentityFile ~/.ssh/id_rsa" &gt;&gt; /root/.ssh/config &amp;&amp;  git clone git@github.com:amitbadheka/Learning-Rails.git] returned a non-zero code: 128
  </code></pre>
  
  <p>So when I use the same key, I could access my repo.</p>
  
  <p>Can anyone tell me what I am missing? </p>