I'm trying to clone private git repository from github. I did a Dockerfile like this:
FROM ubuntu:12.04
RUN apt-get update
RUN apt-get install -y git
RUN mkdir -p /root/.ssh/
ADD ./id_rsa /root/.ssh/id_rsa
RUN git clone [email protected]:usr/repo.git
I use this repo with this key just fine locally, so it seems I'm missing something inside docker.
One more thing I may be missing is that both ~
and $HOME
inside docker point to /
instead of /root
, but I'm not sure if that can be related.
ssh/id_rsa # make sure your domain is accepted RUN touch /root/. ssh/known_hosts RUN ssh-keyscan bitbucket.org >> /root/. ssh/known_hosts RUN git clone [email protected]:your-user/your-repo. git FROM ubuntu # copy the repository form the previous image COPY --from=intermediate /your-repo /srv/your-repo # ...
What's the output of the build process?
Random guess: try to chmod 600
the private key.
If it still doesn't work, try to RUN ssh -v [email protected]
(after adding the key); the output should explain what's happening.
RUN ssh-keyscan github.com >> ~/.ssh/known_hosts
The keyscan works great since it accepts the host. The following complete answer worked:
RUN mkdir -p /root/.ssh
RUN cp /var/my-app/id_rsa /root/.ssh/id_rsa
RUN chmod 600 /root/.ssh/id_rsa
RUN ssh-keyscan github.com >> /root/.ssh/known_hosts
Also as mentioned:
RUN ssh -v [email protected]
^ Great way to debug the flow. That's how I realized I needed the keyscan >> known_hosts
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With