【问题标题】:Why automatic port forwarding? How to prevent VS Code from doing it?为什么要自动端口转发?如何防止 VS Code 这样做?
【发布时间】:2022-10-24 15:34:12
【问题描述】:

我的设置是带有开发容器的 VS Code。当我启动一个生成看起来像 URL 的输出的应用程序时,VS Code 将提取端口号并自动转发该端口。此过程在here 中有详细描述。

我的问题是双重的:

  1. 自动转发端口有什么好处?

  2. 如何有效防止VS Code自动转发任何端口?

    我考虑和测试的解决方案包括使用以下设置:

    {
       // Prevent VS Code's automatic port forwarding
       "remote.autoForwardPorts": false,
       "remote.restoreForwardedPorts": false,
       "remote.portsAttributes": {
          "1-65000": {
             "label": "Application",
             "onAutoForward": "ignore"
          }
       },
    }
    

    我已经在用户级别、开发容器级别(又名远程)和工作区级别尝试了这些设置。此外,我也在devcontainer.json 中尝试过这些设置。我还重建了开发容器以确保应用设置。

    但是,我对这一切都不太幸运。 VS Code 保持自动转发端口。我正在寻找一个持久的解决方案。

【问题讨论】:

  • 你试过这个devcontainer.json 并重建吗?
  • @ikhvjs 是的,我在此过程中也重建了几次开发容器,但无法获得可靠的一致结果。 VS Code 不断转发端口。
  • 您使用的是什么操作系统?如果您使用的是 Windows,源代码是在 Windows 文件系统中还是在 WSL 文件系统中?
  • dev 容器在 Linux 上运行,VS Code 前端在 Windows 上运行。我知道在哪里可以找到设置。我在四个不同的地方更新了它们:用户、工作区、开发容器以及devcontainer.json。我有一些可以工作的开发容器和一些不能工作的容器。我正在寻找决定因素,理想情况下不是 VS Code 中的错误。
  • @ikvvjs 我在devcontainer.json 中尝试了该设置,但行为没有改变。

标签: visual-studio-code vscode-remote vscode-devcontainer


【解决方案1】:

我检查了devcontainer.json reference documentationport attributes

我认为您需要在devcontainer.json 中进行以下设置

忽略值意味着该端口根本不应该被自动转发。

{
  "otherPortsAttributes": { "onAutoForward" : "ignore" }
}

【讨论】:

    猜你喜欢
    • 2022-10-30
    • 2020-08-30
    • 1970-01-01
    • 2022-07-17
    • 2013-08-26
    • 2022-12-04
    • 1970-01-01
    • 2015-01-06
    • 1970-01-01
    相关资源
    最近更新 更多