It is a continuation from Last time. This time, run the python file inside the remote docker container via pycharm. It's a little confusing, so I'll summarize it as follows.
Edit the file locally, but synchronize it remotely
At runtime, make pycharm recognize the python interpreter in remote docker and execute it.
Remote docker recognizes and executes files on the remote
It is the same as here except whether to use docker or docker compose. I wish pycharm could edit the code directly on the remote, but for some reason I can't.
Docker is a client-server model application, and you can use docker by requesting processing from the docker daemon (server). By default, communication is performed through a Unix socket, such as when passing the docker command, but if you set it, you can also communicate through a TCP socket. This allows you to request processing from the local docker daemon remotely. Regarding the mechanism of docker around here, this site was helpful. By the way, it seems that you can also run the server docker remotely by forwarding the local Unix socket to the remote Unix socket.
The reference site is the same, but you can request processing from the remote docker through the tcp socket by executing the following. (Originally, it seems that it is dangerous in the production environment if you do not use the certificate when communicating, but let's set it separately. This area is here /log20141212.html) and the official here are detailed.)
You can hit docker from pycharm via TCP socket by doing the following on the server:
#Modify settings
$ sudo vim /etc/systemd/system/docker.service.d/startup_options.conf
#Contents to be described in the settings
$ cat /etc/systemd/system/docker.service.d/startup_options.conf
[Service]
ExecStart=
ExecStart=/usr/bin/dockerd -H unix:// -H tcp://0.0.0.0:2376
#Load & restart
$ sudo systemctl daemon-reload
$ sudo systemctl restart docker.service
#Check settings
# "/usr/bin/dockerd -H unix:// -H tcp://0.0.0.0:2376"OK if there is
$ service docker status
Redirecting to /bin/systemctl status docker.service
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
Drop-In: /etc/systemd/system/docker.service.d
└─docker-bridge-yj.conf, startup_options.conf
Active: active (running) since Tue 2019-06-18 12:54:47 JST; 4 days ago
Docs: https://docs.docker.com
Main PID: 4595 (dockerd)
Tasks: 26
Memory: 9.2G
CGroup: /system.slice/docker.service
└─4595 /usr/bin/dockerd -H unix:// -H tcp://0.0.0.0:2376
Set the synchronization from the Connection tab of Preference> Build, Execution, Deployment> Deployment.
Enter the user's password in Host: Raspberry pi IP address, User name: raspbian user name, Password. The Root path sets where on the Raspberry Pi is recognized as the "root". (That is, it doesn't have to match the root path / of the Raspberry Pi.) For the Web server URL, enter https: // [IP address of Raspberry Pi].
Next, set from the Mapping tab. Set the local folder you want to synchronize with this Local path :. Also, in Deployment path, specify the path you want to synchronize as ** relative path ** from the Root path set earlier.
If you check Upload changed files automatically to default server from Tools> Deployment> Options, it will be convenient for you to rewrite the files and synchronize them without permission.
The official is here.
Add a remote Docker with Preference> Build, Execution, Deployment> Deployment> Docker. The TCP socket is tcp: // [IP address]: [the number you set earlier].
Click the gear mark from Preference> Project> Project Interpreter to add the Project Interpreter. Select the Docker you set up earlier on the Server. Also, set docker-compose.yml created by yourself in Configuration file (s).
If you RUN from pycharm above, the python interpreter in the docker container should move.
Recommended Posts