简体   繁体   中英

VSCode: cannot remote debug python script on Docker container because the connection fails

I read many similar questions but I couldn't find any answer for me. I also went through the documentation: here and here .

I'm running an Ubuntu container on Windows and I read about the limitation in Networking .

I ran the container with -p 3000:3000

The error => connect ETIMEDOUT

This is my 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/"
            }
          ]
    },

This is my 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"
            }
        }
    ]
}

You can try using the remote extensions as it should handle all of this transparently.

This is the extension for Visual Studio Code to remote debug in containers. You can attach a python script to a running container and it will import all the needed dependencies.

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