简体   繁体   English

Docker:如何使用ssh访问私有github仓库?

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

I'm trying to clone a private repo from github using Docker. 我正在尝试使用Docker克隆来自github的私人仓库。 The problem is that I need to use ssh to access to that repo. 问题是我需要使用ssh来访问该repo。 I added a key in my github project's setting which is used, I suppose, to identify the docker's server. 我在我的github项目设置中添加了一个密钥,我想,它用于识别docker的服务器。

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. 我的问题是我无法弄清楚我应该在Dockerfile中写什么,以便服务器在尝试访问我的github仓库时使用该密钥。 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 我看到了将id_rsa添加到容器中的示例,但我不知道id_rsa存储在其服务器上的位置(如果存在)

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 git@github.com:user/repo.git

How do I access to my private repo from docker's server ? 如何从docker的服务器访问我的私人仓库?

I managed to do this by using ssh-add on the key. 我设法通过在密钥上使用ssh-add来完成此操作。

A "problem" with using multiple RUN instructions is that non-persistent data won't be available at the next RUN . 使用多个RUN指令的“问题”是非持久数据在下一次RUN将不可用。 I managed to log in and use github private repos with 我设法登录并使用github私人回购

RUN eval `ssh-agent -s` && \
    ssh-add id_rsa && \
    git clone git@github.com: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. 通过在单个CMD上使用&&eval进程仍将运行,并且当您连接到github时,ssh-agent已加载密钥。

I hope this helps. 我希望这有帮助。

If you want to use git from the Dockerfile, you need to configure the container in the same way as you would configure your own development machine. 如果要使用Dockerfile中的git ,则需要以与配置自己的开发机器相同的方式配置容器。

I can't really understand which is "their" in "their server", so I'm just guessing. 我无法真正理解“他们的服务器”中哪个是“他们的”,所以我只是在猜测。

When you registered a public key with github, you should have got the private key too. 当您使用github注册公钥时,您也应该拥有私钥。 That's the id_rsa that you see in other examples. 这是你在其他例子中看到的id_rsa

If you can not locate that file, just start over. 如果找不到该文件,请重新开始。 Delete the old key, generate a new one and configure it on github and on your docker build context (in your example, just copy it in the same folder as the Dockerfile). 删除旧密钥, 生成一个新密钥并在github和docker构建上下文中进行配置(在您的示例中,只需将其复制到与Dockerfile相同的文件夹中)。

As a different strategy, you might want to do the checkout outside of the image build process (clone locally and ADD everything to the image). 作为一种不同的策略,您可能希望在图像构建过程之外进行检出(在本地克隆并将所有内容ADD到图像中)。

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

相关问题 如何使用 ssh 在 flutter 中访问私有 repo 包? - How to access private repo packages in flutter using ssh? 在Elastic Beanstalk上为github私有repo访问设置SSH密钥 - Setting up SSH keys for github private repo access on Elastic Beanstalk 使用私有GitHub存储库的CD服务器的SSH密钥管理 - SSH Key management for a CD server using a private GitHub repo 如何通过Docker机密共享SSH密钥以访问私有Github存储库? - How to share SSH key through Docker secrets to access private Github repos? Github:只读访问私有仓库 - Github: readonly access to a private repo 如何使用PhpStorm将公共GitHub存储库推送到私有存储库? - How to push public GitHub repo to private repo using PhpStorm? 如何使用 Pandas 或请求访问 Python 中的私有 Github Repo 文件 (.csv) - How to Access Private Github Repo File (.csv) in Python using Pandas or Requests 尝试授予 Jenkins ssh 访问私有 github 存储库时权限被拒绝 - Permission denied when trying to give Jenkins ssh access to private github repo 如何使用个人访问令牌在 github 操作工作流 (B) 中从不同的存储库 (B) 提交和推送到私有存储库 (A) - How to commit and push to a private repo(A), from a different repo(B), in github actions workflow (B) , using personal access token 将 SVN 用于私有 Github 存储库 - Using SVN for Private Github Repo
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM