In [1]:
import docker
In [2]:
client = docker.from_env(version='1.24', timeout=6)
In [3]:
# client
print(dir(client))
In [4]:
images = client.images
In [5]:
print(dir(images))
In [6]:
print(images.list(), "---\n", images.list(name="jenkins"), "---\n", images.list(all=True),"---\n", images.list(filters={"dangling": False}))
In [7]:
image = images.get("node")
In [8]:
print(image, dir(image))
In [9]:
print(images.list())
In [10]:
containers = client.containers
print(dir(containers))
In [18]:
#在运行的容器
print("running: ",containers.list())
print("all: ", containers.list(all=True))
In [19]:
images.pull("alpine", tag="latest")
Out[19]:
In [20]:
# docker pull alpine后运行
containers.run('alpine', 'echo hello world')
Out[20]: