microsoft / vscode-docker

Docker Extension for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-docker
Other
1.21k stars 517 forks source link

Can't start debug on dockerized Python app in WSL #3817

Closed eladavron closed 1 year ago

eladavron commented 1 year ago

Similar to #2641 and #2313 but adding "debugAdapterHost": "172.17.0.1" or "debugAdapterHost": "localhost" did not solve it for me.

When I try starting a debug session of a dockerized Python Flask app in WSL, in the exact same configuration that used to work flawlessly, starting ~1 week ago it instead shows me this error after a few seconds:

image

I do see it starting both the container:

 *  Executing task: docker-run: debug 

> docker container run --detach --tty --name 'wifidrvpotatofarm-dev' --publish '443:8080/tcp' --mount 'type=bind,source=/home/eavron/.vscode-server/extensions/ms-python.python-2022.20.2/pythonFiles/lib/python/debugpy,destination=/debugpy,readonly' --label 'com.microsoft.created-by=visual-studio-code' --entrypoint 'python3' wifidrvpotatofarm:latest <

8041342216b01346e9bd6cf643d429a7f77d8d7f6bee35ff96039a50759ac492 *  Terminal will be reused by tasks, press any key to close it. 

and the debugpy session:

eavron@eavron-mobl:/mnt/c/Users/eavron/AppData/Local/Programs/Microsoft VS Code$  /usr/bin/env /bin/python /home/eavron/.vscode-server/extensions/ms-azuretools.vscode-docker-1.23.3/resources/python/launcher.py 41979 -- /app/server.py docker wifidrvpotatofarm-dev 
docker exec -d wifidrvpotatofarm-dev python3 /debugpy/launcher host.docker.internal:41979 -- /app/server.py
eavron@eavron-mobl:/mnt/c/Users/eavron/AppData/Local/Programs/Microsoft VS Code$

but it just doesn't seem to be able to connect to the running container (which remains up even after this error):

eavron@eavron-mobl:/mnt/c/Users/eavron/AppData/Local/Programs/Microsoft VS Code$ docker ps
CONTAINER ID   IMAGE                      COMMAND     CREATED         STATUS         PORTS                   NAMES
9d7947e54110   wifidrvpotatofarm:latest   "python3"   2 minutes ago   Up 2 minutes   0.0.0.0:443->8080/tcp   wifidrvpotatofarm-dev

Running the container regularly with its docker-compose works fine.

Here are my launch.json:

{
    "name": "PotatoFarm Debug",
    "type": "docker",
    "request": "launch",
    "preLaunchTask": "docker-run: debug",
    "python": {
        "pathMappings": [
            {
                "localRoot": "${workspaceFolder}/app",
                "remoteRoot": "/app"
            }
        ],
        "projectType": "flask"
    }
}

and tasks.json

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "docker-build",
            "label": "docker-build",
            "platform": "python",
            "dockerBuild": {
                "dockerfile": "${workspaceFolder}/Dockerfile",
                "context": "${workspaceFolder}"
            },
            "problemMatcher": [],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        },
        {
            "type": "docker-run",
            "label": "docker-run: debug",
            "dockerRun": {
                "ports": [
                    {
                        "containerPort": 8080,
                        "hostPort": 443,
                        "protocol": "tcp"
                    }
                ]
            },
            "python": {
                "file": "/app/server.py"
            }
        }
    ]
}

Things I've tried that didn't help:

Versions:

bwateratmsft commented 1 year ago

It seems like the Docker extension finished its part and did the handoff to the Python extension (which does the actual debugging). I've seen this error happen on occasion, but never persistently. I'll take a look and see if I can reproduce, but it might be worth opening this in https://github.com/microsoft/vscode-python as well; they know much more about Python's debugging process than I do.

dbreshears commented 1 year ago

Closing for now as this appears to be an issue in the Python extension. Can re-open if that is not the case.