繁体   English   中英

VSCode:如何从我的开发容器内推送到外部 Git 服务器?

[英]VSCode: how to push to external Git server fom inside my dev container?

我创建了一个Visual Studio Code 开发容器 一切正常,这是一项非常酷的技术,但它无法将我提交的代码推送到外部 Git 服务器。 我正在尝试推送到 BitBucket,但问题与 GitHub 相同。

当我尝试从终端推送时,我收到以下错误消息:

$ git push
ssh: connect to host bitbucket.org port 22: Cannot assign requested address
fatal: Could not read from remote repository.

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

当我尝试使用 VSCode Git 选项卡命令推送时,错误更完整:

Please make sure you have the correct access rights
and the repository exists.
> git ls-tree -l HEAD -- /workspaces/xxxx/.devcontainer/Dockerfile
> git show --textconv HEAD:.devcontainer/Dockerfile
> git push origin master:master
ssh: connect to host bitbucket.org port 22: Cannot assign requested address
fatal: Could not read from remote repository.

如果我在本地重新打开我的工作区,推送将照常进行。

我认为这个配置是自动的。 我的远程仓库是使用 ssh 连接的。

我必须配置什么才能推送我的代码?

行动。 错误的问题。 看起来我的 ISP 决定阻止我到端口 22 的出站连接。啊!!! 我没想到。

我发现 GitHub 和 BitBucket 对神经质的系统管理员都有巧妙的解决方法。

Just add these configurations to your ~/.ssh/config file and make your ssh connections to the external Git servers go through the unblockable https port 443:

Host github.com
  Hostname ssh.github.com
  Port 443

Host bitbucket.org
  Hostname altssh.bitbucket.org
  Port 443

这里有一些额外的提示,用于在使用 VSCode 时与容器共享您的 ssh 凭据

我的猜测是您需要转发 Docker 容器的端口。

在左下角应该有这样的链接到图片

单击没有端口转发(右一个)和十个转发端口 22 的那个。

就我而言,为了推送到开发容器内的远程仓库,我进行了以下更改并且它起作用了。

  1. 确保ForwardAgent yes在您的~/.ssh/config文件中。
  2. 将本地 SSH 密钥添加到代理, ssh-add ~/.ssh/github_rsa
  3. 调用eval "$(ssh-agent -s)"
  4. echo $SSH_AGENT_SOCK ,并确保它不是空字符串
  5. 在您的 devcontainer.json 文件中添加功能gitsshd

devcontainer.json

"features": {
        "git": "os-provided",
        "sshd": "latest"
    },

参考: 使用 SSH 密钥的远程容器

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM