在docker容器中运行pudb

在docker容器中运行pudb

本文介绍了在docker容器中运行pudb的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我更喜欢使用pudb进行python调试.我正在构建在docker容器中运行的python应用程序.

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

有人知道如何使pudb在docker容器中可用吗?

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

谢谢

推荐答案

  • 您需要在Docker容器上安装pudb(可以通过将以下行添加到Dockerfile:RUN pip install pudb中来完成).
  • 您需要打开将要连接到pudb的端口.例如

    • 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.

      • 对于Dockerfile:添加EXPOSE 6900.
      • 对于docker-compose,语法是不同的:

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

      ports: - "6900:6900"

      ports: - "6900:6900"

      您需要在set_trace中添加一行,以使入口点位于Python代码中.例如.from pudb.remote import set_trace; set_trace(term_size=(160, 40), host='0.0.0.0', port=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)

      当代码运行并到达该点时,您可以使用telnet客户端连接到该代码,并像通常进行调试一样使用pudb.在上述情况下,从另一个终端输入telnet 127.0.0.1 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.

      您可以在此处找到具有完整工作示例的存储库: https://github.com/isaacbernat/docker-pudb

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

      这篇关于在docker容器中运行pudb的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 22:39