Running pudb inside docker container

1.3k views Asked by At

I prefer pudb for python debugging. I am building python applications that run inside docker container.

Does any one know how to make pudb available inside docker container?

Thank you

1

There are 1 answers

1
isaacbernat On BEST ANSWER
  • You need to have pudb installed on the Docker container (this may be done adding this line to the Dockerfile: RUN pip install pudb).
  • You need to have the ports where you will connect to pudb open. E.g.

    • For a Dockerfile: add EXPOSE 6900.
    • For docker-compose the syntax is different:

      ports: - "6900:6900"

  • You need to add a line to set_trace where you want the entry point to be in the Python code. E.g. from pudb.remote import set_trace; set_trace(term_size=(160, 40), host='0.0.0.0', port=6900)

  • When the code is running and reaches that point, you can connect into it with a telnet client and use pudb as you normally would to debug. In the case above, from another terminal type telnet 127.0.0.1 6900.

You can find a repository with a full working example here: https://github.com/isaacbernat/docker-pudb