10

I am trying to use the python in a docker container on a remote machine as the interpreter in Pycharm. Since that is a mouthful, here is a diagram:

enter image description here

There is a Jupyter Notebook running in the container, which I am able to connect to through my local browser (although this is just for testing the connection). The command I am using to launch the Docker container is

docker run --runtime=nvidia -it --rm --shm-size=2g -v /home/timo/storage:/storage -v /etc/passwd:/etc/passwd -v /etc/group:/etc/group --ulimit memlock=-1 -p 8888:8888 -p 7722:22 --ipc=host latest:latest

I can forward the port 8888 which the Jupyter notebook is running on with ssh -L 8888:0.0.0.0:8888 BBB.BBB.BBB.BBB and thus use it on the local machine. But I don't much like using Jupyter for developing and would like to use the Python interpreter in the Docker Container in Pycharm.

When I select "Add Python Interpreter" in Pycharm, I get the following options:

enter image description here

The documentation for Pycharm suggests using the "Add Python Interpreter/Docker" tool which looks like this:

enter image description here

However the documentation doesn't say how to set up the Docker container and the connections if the Docker is on a remote machine.

So my questions are: should I use a Unix or a TCP socket to connect to my remote docker? Or should I somehow forward all the relevant ports from the container and use the "SSH Interpreter" option? And if so, how do I set this all up? Am I setting up my Docker Container properly in the first place?

I think I have trawled through every forum and online resource, over the last two days, but have not come any closer to getting this to work. I have also tried to get this to work in Spyder, but to no avail either. So any advice is very appreciated!

Many thanks!

Mr Squid
  • 858
  • 10
  • 26
  • 1
    Perhaps the workaround in https://youtrack.jetbrains.com/issue/PY-33489 may help, PyCharm doesn't support this usecase natively out of the box so some extra mouse clicks are required. Meanwhile, nvidia is not supported as well https://youtrack.jetbrains.com/issue/PY-26429 – Pavel Karateev Jul 23 '19 at 15:57
  • @Pavel_Karateev Thanks for your reply. It is helpful to at least know that this is not trivial and I haven't just been making some stupid mistake. I'll give this a try. – Mr Squid Jul 23 '19 at 23:11
  • @Pavel_Karateev Tried this on my private local machine and it works. However it's not a solution for me, since it requires sudo access which I don't have on the servers I ultimately wish to use. Plus it doesn't seem very secure...thanks anyways. – Mr Squid Jul 24 '19 at 00:46
  • I have just embarked on this as I am trying to do the same. I have been using Remote Container Development with VS Code. Have you guys managed to find a more user-friendly solution that doesn't require sudo on the remote? – jayBana Jul 15 '20 at 19:23

0 Answers0