簡體   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