简体   繁体   English

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

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

I've created a Visual Studio Code development container .我创建了一个Visual Studio Code 开发容器 Everything is working fine, it is a very cool technology, but it fails to push my committed code to an external Git server.一切正常,这是一项非常酷的技术,但它无法将我提交的代码推送到外部 Git 服务器。 I'm trying to push to BitBucket, but the problem would be the same with GitHub.我正在尝试推送到 BitBucket,但问题与 GitHub 相同。

When I try to push from the terminal, I get this error message:当我尝试从终端推送时,我收到以下错误消息:

$ 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.

And when I try to push using VSCode Git tab commands, the errors are more complete:当我尝试使用 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.

If I reopen locally my workspace, the push works as usual.如果我在本地重新打开我的工作区,推送将照常进行。

I thought this configuration was automatic.我认为这个配置是自动的。 My remote repo is connected using ssh.我的远程仓库是使用 ssh 连接的。

What must I configure to be able to push my code?我必须配置什么才能推送我的代码?

Ops.行动。 Wrong question.错误的问题。 It looks like my ISP decided to block my outbound connections to port 22. Argh!!!看起来我的 ISP 决定阻止我到端口 22 的出站连接。啊!!! I didn't expect it.我没想到。

I discovered that both GitHub and BitBucket have clever workarounds to neurotic sysadmins.我发现 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: 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

Here are some extra tips for sharing your ssh credentials with the container when using VSCode.这里有一些额外的提示,用于在使用 VSCode 时与容器共享您的 ssh 凭据

My guess is you need to forward the Port of the Docker Container.我的猜测是您需要转发 Docker 容器的端口。

On the bottom left there should be something like this link to Image在左下角应该有这样的链接到图片

Click on the one that says no Ports Forwarded (Right one) and ten forward the port 22.单击没有端口转发(右一个)和十个转发端口 22 的那个。

In my case, to push to remote repo inside dev container, I made the following changes and it worked.就我而言,为了推送到开发容器内的远程仓库,我进行了以下更改并且它起作用了。

  1. make sure ForwardAgent yes is in your ~/.ssh/config file.确保ForwardAgent yes在您的~/.ssh/config文件中。
  2. add your local SSH keys to the agent, ssh-add ~/.ssh/github_rsa将本地 SSH 密钥添加到代理, ssh-add ~/.ssh/github_rsa
  3. call eval "$(ssh-agent -s)"调用eval "$(ssh-agent -s)"
  4. echo $SSH_AGENT_SOCK , and make sure it's not an empty string echo $SSH_AGENT_SOCK ,并确保它不是空字符串
  5. add features git and sshd in your devcontainer.json file.在您的 devcontainer.json 文件中添加功能gitsshd

devcontainer.json devcontainer.json

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

Reference: Remote Container Using SSH keys参考: 使用 SSH 密钥的远程容器

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

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