【问题标题】:git clone can not reach host inside docker containergit clone 无法访问 docker 容器内的主机
【发布时间】:2016-03-19 16:42:38
【问题描述】:

我很久以前就遇到过这个问题,根本无法解决。谁能帮帮我?

我创建了一个 docker 容器,然后在 docker 内部,我想克隆一个内部 git 存储库:

git clone git@git.xxx.net:ngcsc/ngcsc.git

我得到了这个错误:

ssh: connect to host git.xxx.net port 22: No route to host
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

如果我使用 curl https://git.xxx.net, 我也遇到了错误:

curl: (7) Failed connect to git.xxx.net:443; No route to host

我可以 curl 其他 https 网站,比如 curl https://www.google.com

我不知道为什么有些内部网站可以在 docker 中访问,有些则不能。任何建议表示赞赏

【问题讨论】:

标签: git ssh docker git-clone


【解决方案1】:

我认为由于您使用 ssh url 进行 git clone,您将生成一个 ssh 密钥并在 git 门户上注册它。

GitHub ssh registration

然后您必须在 docker 容器中包含 ssh 密钥并执行 ssh-add keyfile

希望这能解决你的问题

【讨论】:

  • 我猜我使用的 AWS 实例不允许传出 SSH,使用 HTTPS 解决了我的问题
【解决方案2】:

首先,确保你在启动容器的时候已经映射了相关的端口,一般ssh使用端口22或者443,这样你就可以简单的把它们都映射了。

docker run -it -p 22:22 -p 443:443 IMAGE_ID

其次,在 docker 中,您应该生成一个 ssh 密钥对并注册您正在使用的 git 门户。只需使用命令ssh-keygen 即可生成新的密钥对。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多