-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Back-end debugging in Docker #7
Comments
Thanks for the report, I'll take a look into this. |
It seems the solution is quite simple: one can add the following lines in main.py:
and then use such VSCode launch.json config as:
|
I've tried this approach and it's not working for me, at least using the latest ptvsd main.py
launch.json (i'm on windows)
Dockerfile
requirements.txt
|
I cannot help with VSCode, but I'd like to leave an instruction on how to do the same thing when using Pycharm. To debug backend app deployed locally using docker-compose, my preferred way is to use Pycharm's remote debugger. Here is a documentation on how to set it up. Few caveats that require a little explanation when debugging project deployed in a local docker environment:
|
What's up with this @tiangolo ? |
Hello! |
For pycharm i got it working by doing this:
Then to run it:
If anyone knows more about traefik and docker, there is probably an easier way that doesn't require me to add a new backend port and hardcode it in the frontend. Please tell me if there is :) |
In light of @sepharg's suggestion, using debugpy which is the replacement of ptvsd(for VSCode users, or Vim/Emacs+DAP users), adapted to the current structure of the project:
At this point, you should be able to connect to For VSCode users, make the {
"configurations": [
{
"name": "Python: Remote Attach",
"type": "python",
"request": "attach",
"connect": {
"host": "localhost",
"port": 5432
},
"pathMappings": [
{
"localRoot": "${workspaceFolder}",
"remoteRoot": "/app"
}
]
}
]
} This has worked for me, using Docker on Windows (WSL2 engine) and VSCode |
@nmdanny provided excelent instructions, unfortunately a typo on the port number, 5432 is for postgres, they should have been 5678, the default port for debugpy. Another minor issue is in the pathmappings, if the IDE workspace, is the project root folder, should use:
|
@nmdanny's setup works for me - using docker on Ubuntu 20.04 |
Thank you for this project, it's very useful.
One of the missing things is a description of how to debug back-end services in Docker. I couldn't successfully manage how to debug in VSCode (via ptvsd) or PyCharm (via remote debug option). Probably some Traefik config should be changed in order to allow remote connections to interpreter.
The text was updated successfully, but these errors were encountered: