In order to debug our flask app using VSCODE python debugger, follow the following steps:
- Install VSCODE
- In VSCODE Install the following extensions: Microsoft Python Extension, Docker Extension, Microsoft Remote Development A guide for installing VSCODE extensions
- Modify docker-compose.yml: add the following to the ports section in anyway service:
- "5678:5678"
This will add the port mapping exposing it to the debugger. - Modify Dockerfile: remove the following command:
CMD FLASK_APP=anyway flask run --host 0.0.0.0
and add the following commands instead:
RUN pip install debugpy
CMD FLASK_APP=anyway python -m debugpy --listen 0.0.0.0:5678 -m flask run --host 0.0.0.0 -p 5000
- Add the following configuration to .vscode/launch.json:
"configurations": [
{
"name": "ANYWAY Docker: Python - Flask",
"type": "python",
"request": "attach",
"pathMappings": [
{
"localRoot": "${workspaceFolder}/",
"remoteRoot": "/anyway"
}
],
"port": 5678,
"host": "127.0.0.1"
}
]
- Run
docker-compose build
- Run
docker-compose up anyway
- Go to the
RUN
section in VSCODE and chooseANYWAY Docker: Python - Flask
- Happy Debugging!