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.
What I did (my Dockerfile):
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
Output:
Step 12/22 : RUN eval "$(ssh-agent -s)"
---> Running in f9ad80981cee
Agent pid 6
Removing intermediate container f9ad80981cee
---> d773f7ce5917
Step 13/22 : RUN ssh-add -K /root/.ssh/id_rsa
---> 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
As you can see, ssh-agent is started, but keys are not adding in it.
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.