【问题标题】:VSCode: cannot remote debug python script on Docker container because the connection failsVSCode:无法在 Docker 容器上远程调试 python 脚本,因为连接失败
【发布时间】:2020-04-30 18:04:25
【问题描述】:

我阅读了许多类似的问题,但找不到任何适合我的答案。我还浏览了文档:herehere

我在 Windows 上运行一个 Ubuntu 容器,我读到了 limitation in Networking

我使用 -p 3000:3000 运行容器

错误 => 连接 ETIMEDOUT

这是我的 launch.json

"configurations": [
    {
        "name": "Python: Remote Attach",
        "type": "python",
        "request": "attach",
        "port": 3000,
        "host": "172.17.0.2",
        "pathMappings": [
            {
              "localRoot": "${workspaceFolder}/somefolder/somefolder",
              "remoteRoot": "/rootfolder/"
            }
          ]
    },

这是我的tasks.json:

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "docker-build",
            "label": "docker-build",
            "platform": "python",
            "dockerBuild": {
                "tag": "test:latest",
                "dockerfile": "${workspaceFolder}/somefolder/somefolder",
                "context": "${workspaceFolder}",
                "pull": true
            }
        },
        {
            "type": "docker-run",
            "label": "docker-run: debug",
            "dependsOn": ["docker-build"],
            "python": {
                "module": "C:\\...\\somefolder"
            }
        }
    ]
}

【问题讨论】:

  • 你试过 VS Code 的 remote extensions 吗?
  • 嗨,谢谢我采用了你的解决方案,它正在工作。如果您愿意,可以通过链接发布答案。
  • 我之前因为发布基本上只是链接的答案而遇到麻烦,但我们会试一试,看看是否有人反对。
  • 由于没有人提供可以直接解决我的问题的答案,我将暂时接受您的答案作为我的问题的替代和有效解决方案。如果有人反对,我可以删除这个问题。再次感谢。

标签: python visual-studio-code remote-debugging docker-container


【解决方案1】:

您可以尝试使用remote extensions,因为它应该透明地处理所有这些。

This 是 Visual Studio Code 在容器中远程调试的扩展。您可以将 python 脚本附加到正在运行的容器中,它将导入所有需要的依赖项。

【讨论】:

    猜你喜欢
    • 2021-11-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-15
    • 2020-06-15
    • 1970-01-01
    • 2019-08-11
    • 1970-01-01
    相关资源
    最近更新 更多