-
Notifications
You must be signed in to change notification settings - Fork 26
Debugging with VSCode in the docker container
Ralf Peschke edited this page Feb 8, 2021
·
2 revisions
- The python extension from Microsoft should be installed
- Add the debugpy-Package to the dev-requirements. This is done in requirements_development.txt: debugpy==1.2.1 in 12/2020
- Open the debug port for the running container. This is done in docker-compose.dev.yml under ports: - "5678:5678"
- If you want the app, for example openslides-backen, to be ready to be debugged, start it in the Dockerfile-dev with CMD python -m debugpy --listen 0.0.0.0:5678 openslides_backend.
- The only thing you have to do, put the following configuring to the launch.json file inside the .vscode folder. You could open and prepoulate it from the run/debug-pane in VSCode. It will attach to localhost:5678, using the source defined in localRoot.
{
"name": "Python: attach",
"type": "python",
"request": "attach",
"connect": {
"host": "localhost",
"port": 5678
},
"pathMappings": [
{
"localRoot": "${workspaceFolder}/openslides-backend",
"remoteRoot": "/app"
}
]
},
- Start the docker ensemble as usual: make run-dev
- On the prompt start pytest embedded in python debug: python -m debugpy --listen 0.0.0.0:5678 /usr/local/bin/pytest. Pytests starts immediately. If you want it to wait for attaching use python -m debugpy --listen 0.0.0.0:5678 --wait-for-client /usr/local/bin/pytest.
- In the VSCode run/debug pane choose the Python: attach configuration you entered in the launch.json and press the green arrow on the left side or F5 to start the debugger. It will stop on your first breakpoint or on first raised exception, if still enabled as breakpoint.
- Start the docker ensemble from the openslides-repo as usual: make run-dev.
- Now you attach to the openslides-backend.service running on localhost:5678.
Have a look at the project description of debugpy (https://github.com/microsoft/debugpy). There is more you can do, for instance attaching to a running process via PID.