Skip to content

Network Module

This module provides objects for managing docker network instances.

Network

Represents a docker network.

Attributes:

  • name str - Network name.
  • driver str - Network driver.
  • docker_network Optional[DockerNetwork] - Holds an instance of a started docker network.

connect_container

 | def connect_container(container_id: str, container_name: str) -> None

Connect container to network and give it a reachable network alias.

Arguments:

  • container_id str - The containers id.
  • container_name str - The containers name.

containers

 | def containers() -> List[DockerContainer]

Return list of Container objects connected to network.

network_name

 | def network_name() -> str

Network name.

network_id

 | def network_id() -> str

Network short id.

start

 | def start() -> None

Start Docker network.

stop

 | def stop() -> None

Stop Docker network.

WhaorNet

def WhaorNet(name: str = "whaornet", driver: str = "bridge") -> ContextManager[Network]

Context manager which yields a network to connect containers to.

Arguments:

  • name str - Name of network.
  • driver str - Type of network drivier.

Yields:

  • Network - A Docker network.