Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pycharm Remote interpreter on Docker remote: [Errno 2] No such file or directory

As specified in the title I am trying to use Pycharm Professional (2018.2) with a python remote interpreter in a Docker machine hosted on a remote server in my LAN. I created a very simple example by following the help 'https://www.jetbrains.com/help/pycharm/using-docker-as-a-remote-interpreter.html'.

  • Pycharm 2018.2 is installed on a LAN pc (192.168.1.10) on a debian distro;
  • Docker is installed on a LAN debian server (192.168.1.22)

I was able to configure Docker as a remote interpreter, to connect with the Docker service through the Pycharm tool but when I try to run (or debug) the main.py in the Docker container I always get this:

37073edcd9d2:python -u /opt/project/main.py (null): can't open file '/opt/project/main.py': [Errno 2] No such file or directory
Process finished with exit code 2

The execution is certainly done in the remote Docker container but it seems that the file to be executed is not found. I manually attached the local volume as described on various blogs with all possible variations but I always get the same error. These are some specifications of my configuration: docker tool setting

project interpreter setting

Run/Debug Configuration

docker container setting with volume mapping into Run/Debug Configuration

Is missing something?

Tanks. Any help is appreciated!

like image 781
ssboy Avatar asked Nov 08 '22 02:11

ssboy


1 Answers

The problem lies in the Pycharm 'limit' of managing a docker machine on a remote host 'under the hood'. When inserting the volume mapping in the run / debug configuration, it is interpreted as a local path and therefore, in this case, a path that must be present on the remote server. So, for now, the only option is to mount the local path (the folder where the project is located) on the remote host of the Docker service by first sharing it through an SSHFS or NFS service. So ... (1) I shared the Pycharm project folder (local machine ip 192.168.1.10) using NFS; (2) I mounted the shared folder on the server host (on server ip 192.168.1.22; mount -t nfs 192.168.1.10:/home/user/PythonProjects /home/ext-user/mnt/projects) then (3) in the run / debug configuration of Pycharm I mapped the volumes with the path mounted on the remote server ... Run ... the program now runs without any errors. [Run result]

These are some specifications of my new configuration:

Run/Debug Configuration

docker container setting with volume mapping into Run/Debug Configuration

I hope the solution can be useful to other people. I also hope that there are better solutions than mine :-)

like image 183
ssboy Avatar answered Nov 14 '22 22:11

ssboy