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 git@github.com: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.
RUN ssh-keyscan github.com >> ~/.ssh/known_hosts
The keyscan works great since it accepts the host. The following complete answer worked:
Also as mentioned:
^ Great way to debug the flow. That's how I realized I needed the keyscan >> known_hosts
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 git@github.com
(after adding the key); the output should explain what's happening.(Will probably not fit your needs)
There is another approach: https://stackoverflow.com/a/29464430/990356
Go to Settings > Personal access tokens and generate a personal access token with
repo
scope enabled. Now you can dogit clone https://MY_TOKEN@github.com/user-or-org/repo
Pros:
Cons:
To fix this, you can use an environment variable to store the token