PyCharm 在 Docker 中添加远程 Python 解释器

PyCharm add remote Python interpreter inside the Docker

所以我在笔记本电脑上设置了 docker。我正在使用 Boot2Docker,所以我有一级间接访问 docker。在 PyCharm 中,我可以通过 SSH 设置远程 python 解释器,但我不确定如何为只能通过 Boot2Docker 访问的 docker 设置?

好的,那么回答你的问题:

In PyCharm, I can set a remote python interpreter via SSH but I'm not sure how to do it for dockers that can only be accessed via Boot2Docker?

你需要:

  • 确保您的容器中有 SSH 运行ning

有许多包含 SSH 的基础映像。参见:Dockerizing an SSH Daemon

  • 向 Boot2Docker/VirtualBox VM 公开 SSH 服务。

    docker 运行 -d -p 2222:22 myimage ...

  • 设置 PyCharm 以连接到您的 Boot2Docker/VirtualBox 虚拟机。

    boot2docker ip


附加到 运行ning 容器也很容易!

$ boot2docker ssh
$ docker exec -i -t <cid> /bin/bash

其中 <cid> 是容器 ID 或名称(如果您使用 --name