Debugging Flask under gunicorn in docker container



My projects is starting up multiple containers with docker-compose the flask app is running under gunicorn, now is it possible to use pycharm debugger to set breakpoints and use rest of the IDE?

Currently the only way to debug the project is to run containers with docker-compose up command and use pdb.set_trace() to set a breakpoint.



Hi Elizabeth

Thank you for your reply! Unfortunately it did not work since pycharm is throwing error message which state the following: "Failed to find free socket port". This is happening because i am trying to connect remote debugger to docker container which is up on my local machine and uses 5009 port. Could you please comment on this?


Streak Flash Are you using Remote Interpreter or Remote Debug Server?


I am using local virtual environment and a  remote debug server. i've put the .egg file in my docker container and included required library in my python file. When i hit the debug button debugger starts up and waits for connection to my given port. but then i am unable to start the docker container since the port is locked by pychamr debugger


Hi Streak Flash! Is it possible to access host from inside your container? Could you please provide more details about network and port configuration you made? Doesn't selecting another port for Remote Debug Server work? I made a quick setup on mac (btw what is your OS?):

  • pydevd.settrace('docker.for.mac.localhost', port=1234, stdoutToServer=True, stderrToServer=True) inside a Python script
  • interpreter based on the python:latest image (no specific port or network configuration made)
  • run Remote Debug Server
  • run Python script in PyCharm
  • successful connection

Please sign in to leave a comment.