Skip to content

Debugger is not started correctly when debugging containerized Python app in WSL #2641

@tjohanssonn

Description

@tjohanssonn

Hi,

Similar issue as #2313. That solution didn't solve the issue to me. I have tried adding "debugAdapterHost": "172.17.0.1", but it still doesn't work.

Debugger doesn't connect to debugpy when starting my container. The container is built and run, but when handing over to debugpy nothing happens.

  • Python Debug Console is not started.

This is printed in the console, and then nothing more happens.

Executing task: docker-run: debug <

> docker run -dt -P --name "test-dev" --label "com.microsoft.created-by=visual-studio-code" -v "/home/<user>/.vscode-server/extensions/ms-python.python-2020.12.424452561/pythonFiles/lib/python/debugpy:/debugpy:ro" --entrypoint "python" "test:latest" <

094d9d0df53c4814600415523605eee4e444bcff6f5175219aa31808df3e55d8

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

launch.json - I've tried setting host to localhost too.

{
    "configurations": [
        {
            "name": "Docker: Python - General",
            "platform": "python",
            "type": "docker",
            "request": "launch",
            "preLaunchTask": "docker-run: debug",
            "debugAdapterHost": "172.17.0.1",
            "python": {
                "pathMappings": [
                    {
                        "localRoot": "${workspaceFolder}",
                        "remoteRoot": "/app"
                    }
                ],
                "projectType": "general",
                "host": "0.0.0.0",
                "port": 5678
            }
        }
    ]
}

task.json

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

Dockerfile

# For more information, please refer to https://aka.ms/vscode-docker-python
FROM python:3.8-slim-buster

# Keeps Python from generating .pyc files in the container
ENV PYTHONDONTWRITEBYTECODE=1

# Turns off buffering for easier container logging
ENV PYTHONUNBUFFERED=1

# Install pip requirements
COPY requirements.txt .
RUN python -m pip install -r requirements.txt

WORKDIR /app
COPY . /app

# Switching to a non-root user, please refer to https://aka.ms/vscode-docker-python-user-rights
RUN useradd appuser && chown -R appuser /app
USER appuser

# During debugging, this entry point will be overridden. For more information, please refer to https://aka.ms/vscode-docker-python-debug
CMD ["python", "main.py"]

Environment

VSCode

  • Version: 1.52.1 (user setup)
  • Commit: ea3859d4ba2f3e577a159bc91e3074c5d85c0523
  • Date: 2020-12-16T16:34:46.910Z
  • Electron: 9.3.5
  • Chrome: 83.0.4103.122
  • Node.js: 12.14.1
  • V8: 8.3.110.13-electron.0
  • OS: Windows_NT x64 10.0.18363

Running remote VSCode in WSL2

  • Docker extension v1.9.0
  • Python extension v2020.12.424452561

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions