本文整理汇总了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()
示例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}")