Python源码示例:docker.io()
示例1
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
def get_host(self) -> str:
return 'https://index.docker.io/v1/'
示例3
def push(self, client, tag):
client.images.push(tag)
logger.info('Pushed image %s to docker.io', tag)
示例4
def delete_image(self, client, image: 'DockerImage', force=False, **kwargs):
logger.warn('Skipping deleting image %s from docker.io', image.name, force, **kwargs)
示例5
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
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)