Docker Community Forums

Share and learn in the Docker community.

Access container python interpreter without setting up a docker-machine


(Sodjaj) #1

Dear all,

I am trying to add the python interpreter from a docker container to my Pycharm IDE such that I can Pycharm on my host system for code development. I am working on a Centos7. I am trying to solve some numerical problems using the Fenics docker image . Speed is critical, so I would like to avoid running docker container from the docker-machine.

Is it possible to connect to the container without using the docker-machine? If yes how? I can configure a SSH connection to a remote python interpreter in pycharm.

My apologies for a what might be a fairly trivial question. However I am new to the Docker so I am still trying to get some grip of this technology.

Thank you for your help!
Best regards,
Jruij


(Nathan Le Claire) #2

I don’t understand the concern here – containers are very cheap (they’re just isolated Linux processes), and if you already are running Docker, the main overhead (e.g. of running a VM) has been handled already.

Don’t SSH into containers, it’s an antipattern. If you want to spawn a shell process in an existing container then look up the container ID or name using docker ps and do docker exec -ti <container> sh (or bash, python, etc. for the command on the end).


(Sodjaj) #3

Thanks for the reply!

I understand that the docker it self is very light weigh. Actually I like the idea very very much.:slight_smile: However,if I want to use my IDE for development and debugging I need to connect, in my case, to a python interpreter that resides in the container in order to have access to all the libraries in the container.

Now, if I understand correctly, in order to be able to do that I need to create a VM and put the container in there and run it. Then the VM will expose an IP:port number, that I can use to connect to the python interpreter. Will that not be slower than running a container directly in docker?

Secondly, I need to install a Linux VM on my host Linux. Since docker runs on linux without any need for a VM I see this as an unnecessary overhead, Therefore I would like to connect to my container directly in docker.

I have to admit, that I am very new to this technology and it is still a bit overwhelming at the moment.

Thank you for your help!
Kind regards,
Jurij


(David Maze) #4

Unless your host system is really old (I know there is some CentOS 6/RHEL 6 in the wild), you can just run Docker natively. Is there a write-up somewhat that’s leading you to think a VM is necessary?


(Sodjaj) #5

Hi,

thanks for your feedback.

I am running CentOS7, my IDE is Pycharm2016 and I am running the Fenics project docker image on quay (quay.io/fenicsproject/stable:latest).

I was following the instructions on the pyCharm website. I was also trying to use this screencast on youtube. The auther there specifically mentions that you don’t need the VM on linux, but no more than that. I was trying to find more on this, but without success.

I did however manage to expose a port of my container using:
docker run -ti -p 127.0.0.1:2376:2376 quay.io/fenicsproject/stable:latest

Then I added the http;//127.0.0.1:2376 as the API url in Pycharm. Since running on Linux the path to certificate folder is not necessary if http is used instead of https. In this cae I get an exception: java.net.SocketException: Connection reset. Perhaps I should install docker-compose and create the certificate folder and then try again.


(David Maze) #6

[…which has an “API URL” text box, with the example showing http://192.168.99.100:2376.]

Does it work to leave this box totally empty? Or to specify unix:///var/run/docker.sock?

Other forum threads have mentioned tools that only work with a TCP-based Docker socket. This is a serious security issue, and is your IDE requiring you to allow unrestricted unauthenticated root access to your system. The docker daemon command documentation contains instructions for opening network access to the socket; if you do, you really really should make sure that port isn’t accessible at all from the network, possibly setting up iptables rules for it (CentOS will at least block everything by default). -H tcp://127.0.0.1:2375 is probably safe, and you can type http://127.0.0.1:2375 into PyCharm.

This URL is a URL to the Docker daemon itself, not to your application. You have to reconfigure Docker to make it available.