相当与docker run
Params:
实例
>>> from docker import Client
>>> c = Client(base_url='tcp://192.168.1.104:2375')
>>> c.create_container(image='centos',command='echo "examle container"')
{u'Id': u'30b51797743b7b8dd029899bf527797384864fdb3367c18c18748250017f8888',
u'Warnings': None}
查看返回结果
[root@Mysql ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
30b51797743b centos:latest "echo 'examle contai 27 seconds ago silly_goldstine
扩展实例
c.create_container(image="letong/webserver",stdin_open=True,tty=True,command="/usr/bin/supervisord -c /etc/supervisord.conf",volumes=['/data'],ports=[80,22],name="webserver1")
数据绑定实例
c.start(container_id, binds={
'/home/user1/':
{
'bind': '/mnt/vol2',
'ro': False
},
'/var/www':
{
'bind': '/mnt/vol1',
'ro': True
}
})
remove_container
相当于docker rm
Params:
#
实例
>>> from docker import Client
>>> c = Client(base_url='tcp://192.168.1.104:2375')
>>> c.remove_container(container='30b5')
remove_image
相当于docker rmi
Params:
#
实例
>>> from docker import Client
>>> c = Client(base_url='tcp://192.168.1.104:2375')
>>> c.remove_image(image='centos')