Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker: How to access to a private github repo using ssh?

I'm trying to clone a private repo from github using Docker. The problem is that I need to use ssh to access to that repo. I added a key in my github project's setting which is used, I suppose, to identify the docker's server.

My problem is that I can't figure out what I should write in my Dockerfile so that the server use that key when it tries to access to my github repo. I saw examples where id_rsa is added to the container, but I don't know where id_rsa is stored on their server, if it exists

RUN mkdir /root/.ssh/
# can't find the file id_rsa
ADD id_rsa /root/.ssh/id_rsa 
RUN touch /root/.ssh/known_hosts
RUN ssh-keyscan github.com >> /root/.ssh/known_hosts

run git clone [email protected]:user/repo.git

How do I access to my private repo from docker's server ?

like image 849
Carl Levasseur Avatar asked Jul 08 '14 22:07

Carl Levasseur


People also ask

How do I access GitHub repository via SSH?

GitHub SSH config With the public key copied, log into GitHub and go to your account settings. A link exists for SSH and GPG keys. Click on this link, add a GitHub SSH key, paste the value of the public key into the appropriate field, and give your key a creative name.

How do I access a private GitHub repository?

Set up a GitHub SSH key. Add the public SSH key to a private repository's deploy keys. Store the private SSH key in Secret Manager. Submit a build that accesses the key from Secret Manager and uses it to access the private repository.

How do I access docker GitHub?

You can authenticate to GitHub Packages with Docker using the docker login command. To keep your credentials secure, we recommend you save your personal access token in a local file on your computer and use Docker's --password-stdin flag, which reads your token from a local file.


1 Answers

I managed to do this by using ssh-add on the key.

A "problem" with using multiple RUN instructions is that non-persistent data won't be available at the next RUN. I managed to log in and use github private repos with

RUN eval `ssh-agent -s` && \
    ssh-add id_rsa && \
    git clone [email protected]:user/repo.git

By using the &&'s on a single CMD, the eval process will still be running and ssh-agent has the key loaded when you connect to github.

I hope this helps.

like image 191
Marcus Hughes Avatar answered Nov 13 '22 17:11

Marcus Hughes