本文整理匯總了Python中docker.client.Client.kill方法的典型用法代碼示例。如果您正苦於以下問題:Python Client.kill方法的具體用法?Python Client.kill怎麽用?Python Client.kill使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類docker.client.Client
的用法示例。
在下文中一共展示了Client.kill方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: DockerPyClient
# 需要導入模塊: from docker.client import Client [as 別名]
# 或者: from docker.client.Client import kill [as 別名]
#.........這裏部分代碼省略.........
if 'volumes' in entry:
volumes.extend([vol['containerPath'] for vol in entry['volumes'] if 'containerPath' in vol])
volsFrom = [vol['from'] for vol in entry['volumes'] if 'from' in vol]
if len(volsFrom):
kwargs['volumes_from'] = volsFrom
if 'portMappings' in entry:
kwargs['ports'] = [p['containerPort'] for p in entry['portMappings']]
container = self.client.create_container(**kwargs)
self.docker_start(container['Id'], entry)
return container['Id']
def docker_start(self, container, entry=None):
logsBound = False
binds = {}
restart_policy = 'on-failure'
kwargs = {
'container': container,
'binds': binds
}
if entry is not None:
if 'network' in entry:
kwargs['network_mode'] = entry['network']
if 'privileged' in entry:
kwargs['privileged'] = entry['privileged']
if 'volumes' in entry:
volsFrom = []
for vol in entry['volumes']:
if 'from' in vol:
volsFrom.append(vol['from'])
continue
if not 'containerPath' in vol:
self.log.warn('No container mount point specified, skipping volume')
continue
if not 'hostPath' in vol:
# Just a local volume, no bindings
continue
binds[vol['hostPath']] = {
'bind': vol['containerPath'],
'ro': 'mode' in vol and vol['mode'].lower() == 'ro'
}
if vol['containerPath'] == '/var/log/ext':
logsBound = True
if len(volsFrom):
kwargs['volumes_from'] = volsFrom
if 'portMappings' in entry:
portBinds = {}
for pm in entry['portMappings']:
portBinds[pm['containerPort']] = pm['hostPort'] if 'hostPort' in pm else None
kwargs['port_bindings'] = portBinds
if 'links' in entry:
kwargs['links'] = entry['links']
if 'restart' in entry:
restart_policy = entry['restart']
kwargs['restart_policy'] = { 'MaximumRetryCount': 0, 'Name': restart_policy }
if not logsBound:
binds['/var/log/ext/%s' % container] = { 'bind': '/var/log/ext', 'ro': False }
self.client.start(**kwargs);
def docker_signal(self, container, sig='HUP'):
self.client.kill(container, sig)
def docker_restart(self, container):
self.client.restart(container)
def docker_stop(self, container):
self.client.stop(container)
def docker_rm(self, container):
self.client.remove_container(container)
def docker_rmi(self, image):
# Force removal, sometimes conflicts result from truncated pulls when
# dockerup container upgrades/dies
self.client.remove_image(image, force=True)