Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running pudb inside docker container

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

like image 724
DarcliGht Avatar asked Apr 27 '16 09:04

DarcliGht


1 Answers

  • 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

like image 143
isaacbernat Avatar answered Oct 18 '22 17:10

isaacbernat