[英]What is the best and easy way to remotely debug a python code running in a docker container?
I have just started working on python. 我刚刚开始研究python。 I want to debug python code that is running in a docker container .
我想调试在docker容器中运行的python代码。 Can anyone please suggest me what could be the best way to remotely debug this?
任何人都可以建议我什么是远程调试这个的最佳方法? I am open to use any of the IDE like
pycharm
or VS Code
etc. Thanks in advance. 我愿意使用任何IDE如
pycharm
或VS Code
等。提前感谢。
Note: I'm using Mac OS for the development
One technique that I used to debug from within container was to : 我用来从容器内调试的一种技术是:
ENTRYPOINT ["/mydir/mycode.py"]
in the Dockerfile ENTRYPOINT ["/mydir/mycode.py"]
注释入口点ENTRYPOINT ["/mydir/mycode.py"]
docker exec -it <container name> /bin/bash
docker exec -it <container name> /bin/bash
Other technique could be to expose the remote debugging port on the docker container using docker expose command which will allow pycharm to connect to the code. 其他技术可能是使用docker expose命令暴露docker容器上的远程调试端口,这将允许pycharm连接到代码。 A similiar approach is discussed here.
这里讨论一种类似的方法。
https://medium.com/@furkanpur/remote-python-debug-to-docker-container-over-ssh-by-using-pycharm-44a9b6e82206 https://medium.com/@furkanpur/remote-python-debug-to-docker-container-over-ssh-by-using-pycharm-44a9b6e82206
Expanding on what piy26 mentioned regarding exposing a remote docker port, I think pudb is very apt for the task. 扩展了piy26提到的有关暴露远程docker端口的内容,我认为pudb非常适合这项任务。 I wrote a github repository with a simple example and step by step instructions you can clone and try out https://github.com/isaacbernat/docker-pudb
我写了一个github存储库,其中包含一个简单的示例和一步一步的说明,您可以克隆并试用https://github.com/isaacbernat/docker-pudb
There is more info on this other answer: Running pudb inside docker container 关于这个其他答案的更多信息:在docker容器内运行pudb
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.