服务器:centos7.3
查看服务器docker容器
IMAGE_name:centos:7
修改服务器docker.service配置文件(将下图中的14行改为15行)
vim /usr/lib/systemd/system/docker.service
重新加载配置文件
systemctl daemon-reload
重启docker
systemctl restart docker
docker安全文档:保护Docker守护进程套接字
https://docs.docker.com/engine/security/https/
开启服务器tcp:2375端口
下载docker
pip install docker
Python调用Docker API
import docker
client = docker.DockerClient(base_url='tcp://服务器ip:2375')
"""
DockerClient()
base_url (str): URL to the Docker server. For example,
``unix:///var/run/docker.sock`` or ``tcp://127.0.0.1:1234``.
version (str): The version of the API to use. Set to ``auto`` to
automatically detect the server's version. Default: ``1.35``
timeout (int): Default timeout for API calls, in seconds.
tls (bool or :py:class:`~docker.tls.TLSConfig`): Enable TLS. Pass
``True`` to enable it with default options, or pass a
:py:class:`~docker.tls.TLSConfig` object to use custom
configuration.
user_agent (str): Set a custom user agent for requests to the server.
credstore_env (dict): Override environment variables when calling the
credential store process.
"""
cls = client.containers.run("centos:7", "ls") #(IMAGE_name,cmd)
print(cls) #b'anaconda-.....