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


Python docker.types方法代碼示例

本文整理匯總了Python中docker.types方法的典型用法代碼示例。如果您正苦於以下問題:Python docker.types方法的具體用法?Python docker.types怎麽用?Python docker.types使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在docker的用法示例。


在下文中一共展示了docker.types方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: docker_network

# 需要導入模塊: import docker [as 別名]
# 或者: from docker import types [as 別名]
def docker_network(self) -> Iterator[Network]:
        """
        Return a Docker network.
        """
        client = docker.from_env(version='auto')
        ipam_pool = docker.types.IPAMPool(
            subnet='172.28.0.0/16',
            iprange='172.28.0.0/24',
            gateway='172.28.0.254',
        )
        # We use the default container prefix so that the
        # ``minidcos docker clean`` command cleans this up.
        prefix = Docker().container_name_prefix
        random = uuid.uuid4()
        name = '{prefix}-network-{random}'.format(prefix=prefix, random=random)
        network = client.networks.create(
            name=name,
            driver='bridge',
            ipam=docker.types.IPAMConfig(pool_configs=[ipam_pool]),
            attachable=False,
        )
        try:
            yield network
        finally:
            network.remove() 
開發者ID:dcos,項目名稱:dcos-e2e,代碼行數:27,代碼來源:test_docker.py

示例2: ensure_local_net

# 需要導入模塊: import docker [as 別名]
# 或者: from docker import types [as 別名]
def ensure_local_net(
        network_name: str = DOCKER_STARCRAFT_NETWORK,
        subnet_cidr: str = SUBNET_CIDR
) -> None:
    """
    Create docker local net if not found.

    :raises docker.errors.APIError
    """
    logger.info(f"checking whether docker has network {network_name}")
    ipam_pool = docker.types.IPAMPool(subnet=subnet_cidr)
    ipam_config = docker.types.IPAMConfig(pool_configs=[ipam_pool])
    networks = docker_client.networks.list(names=DOCKER_STARCRAFT_NETWORK)
    output = networks[0].short_id if networks else None
    if not output:
        logger.info("network not found, creating ...")
        output = docker_client.networks.create(DOCKER_STARCRAFT_NETWORK, ipam=ipam_config).short_id
    logger.debug(f"docker network id: {output}") 
開發者ID:Games-and-Simulations,項目名稱:sc-docker,代碼行數:20,代碼來源:docker_utils.py


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