title: How to deploy code from Github using deploy key in Docker?
body: <p>I want to pull code from Github into my Docker image while building. I have a deploy key generated from the repository, but it seems to me the ssh-agent is not working on my Docker image. </p>
  
  <p>What I did (my Dockerfile):</p>
  
  <pre><code>FROM python:2.7-stretch
  ADD ./id_rsa /root/.ssh/id_rsa
  RUN eval "$(ssh-agent -s)"
  RUN ssh-add -K /root/.ssh/id_rsa
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>Step 12/22 : RUN eval "$(ssh-agent -s)"
   ---&gt; Running in f9ad80981cee
  Agent pid 6
  Removing intermediate container f9ad80981cee
   ---&gt; d773f7ce5917
  Step 13/22 : RUN ssh-add -K /root/.ssh/id_rsa
   ---&gt; Running in 95efeed6a7ad
  Could not open a connection to your authentication agent.
  The command '/bin/sh -c ssh-add -K /root/.ssh/id_rsa' returned a non-zero code: 2
  </code></pre>
  
  <p>As you can see, ssh-agent is started, but keys are not adding in it.</p>
  
  <p>If I skip the ssh-add step then my git pull fails later because of privileges, which is failing as expected as no authentication happened. </p>