Reputation: 4779
I have been looking for a way to start a python debugger so I can debug my flask app which is being executed with gunicorn inside a docker container and then connect to it with my VSCode from outside.
But I dont find any solutions. In fact someone here suggests that it is not possible at all?
Is there a way to debug my flask app executed by gunicorn?
Upvotes: 2
Views: 1739
Reputation: 4779
So it looks like this is very difficult, if not impossible atm, to do with gunicorn. So what I did was
debug_app.py
file in my project with :from myapp.api import create_app if __name__=="__main__": app = create_app() app.run('0.0.0.0', 8000, debug=False)
docker-compose
file:api-debug: image: "myapp:latest" restart: on-failure:3 environment: volumes: - ./:/usr/src/app depends_on: - rabbitmq - redis - mongo tty: true stdin_open: true command: tail -F anything ports: - 8000:8000
VSCode
with the Remote Container
pluggin i attached to that container. This starts a new VSCode window and shows you the files inside the container.Note Since the VSCode is now connected to the container I had to re-install the Python extension (you can look this up but it is easy just go to pluggins and re-install to container)
launch.json
inside the container to run the degub_app.py
that I mentioned above like this:{ "version": "0.2.0", "configurations": [ { "name": "Python: Debug API", "type": "python", "request": "launch", "program": "${workspaceFolder}my_path/debug_api.py", "console": "integratedTerminal", "justMyCode": false } ] }
Upvotes: 3