git clone 无法访问 docker 容器内的主机

标签 git ssh docker git-clone

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

我创建了一个 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/

相关文章:

r - 如何使用 PAT 从私有(private) git 存储库安装 R 软件包?

git - 将旧 git 历史记录添加到新存储库

azure - 在 Azure Devops SSH 任务中运行 `sudo` 命令的安全方法

python - 无法使用 Fabric 和 nohup 真正后台 SSH 隧道

ruby-on-rails - Capistrano 和 GitHub 私有(private) repo - 权限被拒绝(公钥)

mysql - WordPress docker 容器不以 mysql :latest image 开头

mysql - Git Bash 2.5 无法连接到 mysql

git - 在同一个分支上工作,如何在不丢失更改的情况下进行 pull ?

openstack - OpenStack上的Docker驱动程序可以与libvirt.LibvirtDriver共存吗?

docker - Docker镜像中的RStudio无法处理某些库