smoyano
smoyano

Reputation: 67

Clone private Github repos from Docker container

I need to create a Docker image that will clone a Github repo (send as parameter) and will perform some operations with it. For public repos I have no problems, but with private repos, how can I clone them inside my Docker container?

Upvotes: 1

Views: 99

Answers (1)

dgaviola
dgaviola

Reputation: 2469

We have done the following:

  • Create a GitHub account that will be used to read repos
  • Create a private key for this account
  • Ask people who want us to read they repo, add this user to the repo with read-only access

Then, in our Docker image that needs to read the repo, we have the following:

COPY github.pub /root/.ssh/id_rsa.pub
RUN chmod 700 /root/.ssh/id_rsa.pub
COPY github /root/.ssh/id_rsa
RUN chmod 700 /root/.ssh/id_rsa
RUN chown -R root:root /root/.ssh
RUN touch /root/.ssh/known_hosts
RUN echo "Host github.com\n\tStrictHostKeyChecking no\n" >> /root/.ssh/config

Where guthub.pub and github are the files of your SSH key.

With this mechanism, you just need to ask them to add you GitHub account as reader of the repo, and you don't need to ask people for private keys or more complex setup, which is very convenient.

Upvotes: 3

Related Questions