简体   繁体   English

在docker容器内运行pudb

[英]Running pudb inside docker container

I prefer pudb for python debugging. 我更喜欢pudb进行python调试。 I am building python applications that run inside docker container. 我正在构建在docker容器内运行的python应用程序。

Does any one know how to make pudb available inside docker container? 有没有人知道如何在docker容器内制作pudb?

Thank you 谢谢

  • You need to have pudb installed on the Docker container (this may be done adding this line to the Dockerfile: RUN pip install pudb ). 您需要在Docker容器上安装pudb(这可以将此行添加到Dockerfile: RUN pip install pudb )。
  • You need to have the ports where you will connect to pudb open. 您需要将端口连接到pudb open。 Eg 例如

    • For a Dockerfile: add EXPOSE 6900 . 对于Dockerfile:添加EXPOSE 6900
    • For docker-compose the syntax is different: 对于docker-compose,语法不同:

      ports: - "6900:6900"

  • You need to add a line to set_trace where you want the entry point to be in the Python code. 您需要在set_trace中添加一行,以使入口点位于Python代码中。 Eg from pudb.remote import set_trace; set_trace(term_size=(160, 40), host='0.0.0.0', port=6900) 例如from pudb.remote import set_trace; set_trace(term_size=(160, 40), host='0.0.0.0', port=6900) 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. 当代码运行并到达该点时,您可以使用telnet客户端连接它并像通常那样使用pudb进行调试。 In the case above, from another terminal type telnet 127.0.0.1 6900 . 在上面的例子中,从另一个终端类型telnet 127.0.0.1 6900

You can find a repository with a full working example here: https://github.com/isaacbernat/docker-pudb 你可以在这里找到一个包含完整工作示例的存储库: https//github.com/isaacbernat/docker-pudb

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM