當前位置: 首頁>>代碼示例>>Python>>正文


Python docker.io方法代碼示例

本文整理匯總了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 
開發者ID:TomasTomecek,項目名稱:sen,代碼行數:31,代碼來源:docker_backend.py

示例2: get_host

# 需要導入模塊: import docker [as 別名]
# 或者: from docker import io [as 別名]
def get_host(self) -> str:
        return 'https://index.docker.io/v1/' 
開發者ID:zyfra,項目名稱:ebonite,代碼行數:4,代碼來源:base.py

示例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) 
開發者ID:zyfra,項目名稱:ebonite,代碼行數:5,代碼來源:base.py

示例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) 
開發者ID:zyfra,項目名稱:ebonite,代碼行數:4,代碼來源:base.py

示例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) 
開發者ID:Autodesk,項目名稱:molecular-design-toolkit,代碼行數:28,代碼來源:configuration.py

示例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) 
開發者ID:anchore,項目名稱:anchore,代碼行數:58,代碼來源:anchore_utils.py


注:本文中的docker.io方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。