[英]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.