Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dockerfile for cloning private git repo

Tags:

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.

like image 764
Konstantine Rybnikov Avatar asked Oct 28 '13 19:10

Konstantine Rybnikov


People also ask

How do I clone a Dockerfile repository?

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 # ...


2 Answers

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.

like image 96
jpetazzo Avatar answered Oct 19 '22 15:10

jpetazzo


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

like image 41
Dan Sabin Avatar answered Oct 19 '22 13:10

Dan Sabin