Context: Python app needs a database and our database is setup through Docker.
In VS Code docs,
- Add debugpy to your requirements.txt file:
✅ Done
- Add the following code snippet to the file that you wish to debug:
import debugpy # noqa
debugpy.listen(("0.0.0.0", 5678))
debugpy.wait_for_client()
✅ I added the code at the end of main.py
debugpy.listen(("0.0.0.0", 5678))
❓ What is the difference between 0.0.0.0 (the "host" that we need to specify to make it work) and 127.0.0.1 (the default)?
Read networking - What's the difference between 127.0.0.1 and 0.0.0.0? - Super User
Add a Python: Remote Attach configuration to launch.json in the .vscode folder: ...
✅ Done
Modify the docker-compose.yml file to expose the debugger port by adding 5678:5678 to the ports section. If you are using docker run to run your container from the terminal, you must append -p 5678:5678.
✅ I added "5678:5678" in backend's ports AND changed port setting in Traefik.