本文整理汇总了Python中docker.io方法的典型用法代码示例。如果您正苦于以下问题:Python docker.io方法的具体用法?Python docker.io怎么用?Python docker.io使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类docker
的用法示例。
在下文中一共展示了docker.io方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: layers
# 需要导入模块: import docker [as 别名]
# 或者: from docker import io [as 别名]
def layers(self):
"""
similar as parent images, except that it uses /history API endpoint
:return:
"""
# sample output:
# {
# "Created": 1457116802,
# "Id": "sha256:507cb13a216097710f0d234668bf64a4c92949c573ba15eba13d05aad392fe04",
# "Size": 204692029,
# "Tags": [
# "docker.io/fedora:latest"
# ],
# "Comment": "",
# "CreatedBy": "/bin/sh -c #(nop) ADD file:bcb5e5c... in /"
# }
try:
response = self.d.history(self.image_id)
except docker.errors.NotFound:
raise NotAvailableAnymore()
layers = []
for l in response:
layer_id = l["Id"]
if layer_id == "<missing>":
layers.append(DockerImage(l, self.docker_backend))
else:
layers.append(self.docker_backend.get_image_by_id(layer_id))
return layers
示例2: get_host
# 需要导入模块: import docker [as 别名]
# 或者: from docker import io [as 别名]
def get_host(self) -> str:
return 'https://index.docker.io/v1/'
示例3: push
# 需要导入模块: import docker [as 别名]
# 或者: from docker import io [as 别名]
def push(self, client, tag):
client.images.push(tag)
logger.info('Pushed image %s to docker.io', tag)
示例4: delete_image
# 需要导入模块: import docker [as 别名]
# 或者: from docker import io [as 别名]
def delete_image(self, client, image: 'DockerImage', force=False, **kwargs):
logger.warn('Skipping deleting image %s from docker.io', image.name, force, **kwargs)
示例5: reset_compute_engine
# 需要导入模块: import docker [as 别名]
# 或者: from docker import io [as 别名]
def reset_compute_engine():
"""Read the configuration dict at ``moldesign.compute.config`` and set up compute engine
Sets the module-level variable ``default_engine``.
Returns:
dict: copy of the config dictionary used to set the engine
"""
from moldesign import compute
compute.default_engine = None
if config.engine_type == 'docker':
connect_docker()
elif config.engine_type == 'subprocess':
connect_subprocess()
elif config.engine_type in ('ccc', 'docker-machine'):
raise ValueError('Computational engine type "%s" is no longer supported by MDT. '
'Please install docker (https://docker.io) and set: \n'
' engine_type: docker'
'in ~/.moldesign/moldesign.yml')
else:
raise ValueError('Unrecognized engine %s' % config.engine_type)
示例6: run_command_in_container
# 需要导入模块: import docker [as 别名]
# 或者: from docker import io [as 别名]
def run_command_in_container(image=None, cmd="echo HELLO WORLD", fileget=None, fileput=None):
if not image or not cmd:
raise Exception("Invalid input: image="+str(image)+" cmd="+str(cmd))
try:
imageId = discover_imageId(image)
except Exception as err:
print str(err)
return(list())
olines = list()
fbuf = ""
try:
docker_cli = contexts['docker_cli']
container = docker_cli.create_container(image=image, command="/bin/bash -c '"+cmd+"'", tty=False)
docker_cli.create_container(image=image, command="/bin/bash -c '"+cmd+"'", tty=False)
if fileput:
try:
TFH=open(fileput, 'r')
dat = TFH.read()
TFH.close()
docker_cli.put_archive(container.get('Id'), "/", dat)
except Exception as err:
traceback.print_exc()
print str(err)
pass
response = docker_cli.start(container=container.get('Id'))
output = docker_cli.logs(container=container.get('Id'), stdout=True, stderr=True, stream=True)
for l in output:
olines.append(l)
if fileget:
try:
tstream,stat = docker_cli.get_archive(container, fileget)
TFH = io.BytesIO(tstream.data)
tar=tarfile.open(fileobj=TFH, mode='r', format=tarfile.PAX_FORMAT)
for member in tar.getmembers():
fbuf = tar.extractfile(member).read()
tar.close()
TFH.close()
except Exception as err:
fbuf = ""
pass
except Exception as err:
raise err
finally:
try:
docker_cli.remove_container(container=container.get('Id'), force=True)
except:
pass
return(olines, fbuf)