- Client, Windows, Python 3.5, pycharm
- Server, CentOS7.2, Docker 18.09.0
1. Docker open remote connection, modify /usr/lib/systemd/system/docker.service files.
vim /usr/lib/systemd/system/docker.service
Find [Service] in the file
[Service]
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock
2. After the modification, Docker needs to read the configuration file and restart the Docker service.
systemctl daemon-reload
systemctl restart docker
3. Open the docker remote service connection port. Note that this machine system is CentOS7.
Firewall-CMD-Zone = Public-ADD-PORT = 2375/TCP-PerManent
Firewall-CMD-RELOAD
#Can be opened by the following command to see if 2375/TCP is turned on.
Firewall-CMD-List-ALL
4. Install docker in pycharm
pip install docker
In setting, check whether the docker is installed. If not, search in the Install Package after searching in the+number on the right.
5. Test connection
import docker
import json
client = docker.DockerClient(base_url='tcp://192.168.102.11:2375')
cls = client.containers.run("ubuntu", "echo hello world")