[Python] PyCharm remote debug in a docker container

Discussão em 'Python' iniciado por Stack, Julho 17, 2025.

  1. Stack

    Stack Membro Participativo

    I'm having an hard time trying to figure out how to setup a remote debug of a python app (Flask) running in a Docker container. Specifically I'm using docker-compose, PyCharm professional and python 3.5. This is what I've done so far:

    • I copied "pycharm-debug-py3k.egg" into the project folder

    • I added the following lines in the wsgi.py file:

      import sys
      sys.path.append('../pycharm-debug-py3k.egg')
      import pydevd
      pydevd.settrace('0.0.0.0', port=8200, stdoutToServer=True, stderrToServer=True)

    • I created a remote debug configuration in PyCharm (by mapping the path of my local machine project path to the one in the docker container)

    by running the debug configuration (click on the bug icon) from PyCharm it prints (and hangs):

    Starting debug server at port 4200
    Use the following code to connect to the debugger:
    import pydevd
    pydevd.settrace('0.0.0.0', port=4200, stdoutToServer=True, stderrToServer=True)
    Waiting for process connection...


    ...and in the docker container logs I read:


    Could not connect to 0.0.0.0: 4200
    ​

    What should I do? (My goal is to be able to add breakpoints in PyCharm and stop the execution of the docker container app in order to debug it)

    Continue reading...

Compartilhe esta Página