-
|
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. |
Beta Was this translation helpful? Give feedback.
Replies: 11 comments
-
|
Thanks for the report, I'll take a look into this. |
Beta Was this translation helpful? Give feedback.
-
|
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: |
Beta Was this translation helpful? Give feedback.
-
|
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 |
Beta Was this translation helpful? Give feedback.
-
|
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:
|
Beta Was this translation helpful? Give feedback.
-
|
What's up with this @tiangolo ? |
Beta Was this translation helpful? Give feedback.
-
|
Hello! |
Beta Was this translation helpful? Give feedback.
-
|
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 :) |
Beta Was this translation helpful? Give feedback.
-
|
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 |
Beta Was this translation helpful? Give feedback.
-
|
@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: |
Beta Was this translation helpful? Give feedback.
-
|
@nmdanny's setup works for me - using docker on Ubuntu 20.04 |
Beta Was this translation helpful? Give feedback.
-
|
Thanks @nmdanny and @okz for your solutions. It works for me. |
Beta Was this translation helpful? Give feedback.
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: