Run a Python file inside a Docker container on a remote Raspbian via PyCharm

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.

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 settings on Raspbian

To access Docker services

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.

Setting

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

PyCharm remote and local file synchronization

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].

スクリーンショット 2019-12-21 1.11.05.png

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.

スクリーンショット 2019-12-21 1.11.58.png

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.

スクリーンショット 2019-12-21 2.22.07.png

Setting up a Python interpreter using Docker-compose

The official is here.

Docker settings

Add a remote Docker with Preference> Build, Execution, Deployment> Deployment> Docker. The TCP socket is tcp: // [IP address]: [the number you set earlier].

スクリーンショット 2019-12-21 2.07.00.png

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).

スクリーンショット 2019-12-21 2.06.40.png

If you RUN from pycharm above, the python interpreter in the docker container should move.

Recommended Posts

Run a Python file inside a Docker container on a remote Raspbian via PyCharm
Run Matplotlib on a Docker container
Run matplotlib on a Windows Docker container
Try Python interactive mode inside a Docker container
Run a Python file with relative import in PyCharm
Run TensorFlow Docker Image on Python3
Run a local script on a remote host
Run Python code on A2019 Community Edition
Run a Python web application with Docker
Run Jupyter notebook on a remote server
Create a shortcut to run a Python file in VScode on your terminal
Periodically run a python program on AWS Lambda
Use the Kaggle API inside a Docker container
Run a Python file from html using Django
How to run a Django application on a Docker container (development and production environment)
Use python in Docker container as Pycharm interpreter
A memorandum to run a python script in a bat file
How to build a Django (python) environment on docker
Launch Django on a Docker container with docker-compose up
Carry a Docker container
Install Python 3.6 on Docker
How to run a Python file at a Windows 10 command prompt
[Django] Build a Django container (Docker) development environment quickly with PyCharm
Run Openpose on Python (Windows)
Run python with PyCharm (Windows)
Run Tensorflow 2.x on Python 3.7
Run Python CGI on CORESERVER
Run unix command on python
Run IPython Notebook on Docker
Use Python on Windows (PyCharm)
Build a Python environment on your Mac with Anaconda and PyCharm
Create a shell script to run the python file multiple times
Create a Docker container image with JRE8 / JDK8 on Amazon Linux