PyCharm在Docker中添加远程Python解释器 [英] PyCharm add remote Python interpreter inside the Docker
问题描述
因此,我在笔记本电脑上设置了一个docker.我正在使用Boot2Docker,因此我可以使用一种间接方式来访问docker.在PyCharm中,我可以通过SSH设置远程python解释器,但是我不确定如何对只能通过Boot2Docker访问的docker进行设置?
So I have set up a docker on my laptop. I'm using Boot2Docker so I have one level of indirection to access the 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?
推荐答案
好的,请回答您的问题:
Okay so to answer your question(s):
在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
有许多包含SSH的基本映像.请参阅:对SSH守护进程进行Docker化
There are many base images that include SSH. See: Dockerizing an SSH Daemon
-
将SSH服务公开到Boot2Docker/VirtualBox VM.
Expose the SSH service to the Boot2Docker/VirtualBox VM.
docker run -d -p 2222:22 myimage ...
docker run -d -p 2222:22 myimage ...
设置PyCharm以连接到Boot2Docker/VirtualBox VM.
Setup PyCharm to connect to your Boot2Docker/VirtualBox VM.
boot2docker ip
boot2docker ip
附加到正在运行的容器也很容易!
Attaching to a running container is easy too!
$ boot2docker ssh
$ docker exec -i -t <cid> /bin/bash
其中<cid>
是容器ID或名称(如果使用--name
,则为.
Where <cid>
is the Container ID or Name (if you used --name
.
这篇关于PyCharm在Docker中添加远程Python解释器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!