简体   繁体   中英

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

I've created a Visual Studio Code development container . Everything is working fine, it is a very cool technology, but it fails to push my committed code to an external Git server. I'm trying to push to BitBucket, but the problem would be the same with 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:

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.

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!!! I didn't expect it.

I discovered that both GitHub and BitBucket have clever workarounds to neurotic sysadmins.

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.

My guess is you need to forward the Port of the Docker Container.

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.

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.
  2. add your local SSH keys to the agent, ssh-add ~/.ssh/github_rsa
  3. call eval "$(ssh-agent -s)"
  4. echo $SSH_AGENT_SOCK , and make sure it's not an empty string
  5. add features git and sshd in your devcontainer.json file.

devcontainer.json

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

Reference: Remote Container Using SSH keys

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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