VSCode:由于连接失败,无法在Docker容器上远程调试python脚本。

问题描述 投票:0回答:1

我看了很多类似的问题,但我找不到适合自己的答案。我也去看了文档。这里此处.

我在Windows上运行Ubuntu容器,我读到了关于 网络的局限性.

我用-p 3000:3000运行了这个容器。

错误=>连接ETIMEDOUT。

这是我的启动.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"
            }
        }
    ]
}
python visual-studio-code remote-debugging docker-container
1个回答
0
投票

你可以尝试使用 远程扩展 因为它应该透明地处理这一切。

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

© www.soinside.com 2019 - 2024. All rights reserved.