Skip to content

docker network

NetworkCLI

connect

connect(network, container, alias=None, driver_options=[], ip=None, ip6=None, links=[])

Connect a container to a network

PARAMETER DESCRIPTION
network

The network to connect to

TYPE: ValidNetwork

container

The container to connect

TYPE: ValidContainer

alias

Add network-scoped alias for the container

TYPE: Optional[str] DEFAULT: None

driver_options

Driver options for the network

TYPE: List[str] DEFAULT: []

ip

IPv4 address (e.g., "172.30.100.104")

TYPE: Optional[str] DEFAULT: None

ip6

IPv6 address (e.g., "2001:db8::33")

TYPE: Optional[str] DEFAULT: None

links

Add links to other containers

TYPE: List[ValidContainer] DEFAULT: []

create

create(name, attachable=False, driver=None, gateway=None, subnet=None, labels={}, options=[])

Creates a Docker network.

PARAMETER DESCRIPTION
name

The name of the network

TYPE: str

Returns

A `python_on_whales.Network`.

disconnect

disconnect(network, container, force=False)

Disconnect a container from a network

PARAMETER DESCRIPTION
network

The name of the network.

TYPE: ValidNetwork

container

The container to disconnect.

TYPE: ValidContainer

exists

exists(network)

Check if a network exists

PARAMETER DESCRIPTION
network

The name of the network.

TYPE: ValidNetwork

inspect

inspect(x)

Returns a python_on_whales.Network object from a string (id or network name).

PARAMETER DESCRIPTION
x

One id or network name or a list of ids or network names.

TYPE: Union[str, List[str]]

Returns

One or a list of `python_on_whales.Network`.

list

list(filters={})

List all the networks available.

PARAMETER DESCRIPTION
filters

Filters as strings or list of strings.

TYPE: Dict[str, str] DEFAULT: {}

Returns

List of `python_on_whales.Network`.

prune

prune(filters={})

Remove Docker networks which are not used by any containers.

PARAMETER DESCRIPTION
filters

Filters as strings or list of strings.

TYPE: Dict[str, str] DEFAULT: {}

remove

remove(networks)

Removes a Docker network

PARAMETER DESCRIPTION
networks

One or more networks.

TYPE: Union[ValidNetwork, List[ValidNetwork]]