简体   繁体   English

从Docker容器克隆私有Github存储库

[英]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. 我需要创建一个Docker映像,该映像将克隆Github存储库(作为参数发送)并对其执行一些操作。 For public repos I have no problems, but with private repos, how can I clone them inside my Docker container? 对于公共存储库,我没有问题,但是对于私有存储库,如何将其克隆到Docker容器中?

We have done the following: 我们已经完成了以下工作:

  • Create a GitHub account that will be used to read repos 创建一个将用于读取存储库的GitHub帐户
  • 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: 然后,在需要读取存储库的Docker映像中,我们具有以下内容:

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. 其中guthub.pubgithub是您的SSH密钥的文件。

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. 通过这种机制,您只需要让他们将您的GitHub帐户添加为该存储库的读取者即可,而无需要求人们提供私钥或更复杂的设置,这非常方便。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM