我很久以前就遇到过这个问题,根本无法解决。谁能给我一些帮助?
我创建了一个 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 内部访问,有些则不能。任何建议表示赞赏
最佳答案
我认为由于您将 ssh url 用于 git clone,因此您将生成一个 ssh key 并在 git 门户上注册它。
GitHub ssh registration
然后您必须在 docker 容器中包含 ssh key 并执行 ssh-add keyfile
希望这能解决你的问题
关于git clone 无法访问 docker 容器内的主机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36098037/