networks — Docker Network Management¶
- networks.anonymous_network(client: DockerClient, *args, **kwargs) Network[source]¶
Create an anonymous network with a random name.
- Parameters:
client – A docker client to use to create the network.
*args – Arguments to pass to the
NetworkCollection.createmethod.**kwargs – Keyword arguments to pass to the
NetworkCollection.createmethod.
- Returns:
A new anonymous network.
- networks.temp_network(client: DockerClient, name: str | None = None, *args, **kwargs) AbstractContextManager[Network][source]¶
Context manager to create and remove a temporary network.
- Parameters:
client – A docker client to use to manage the network.
name – The name of the network. If
None, a random name will be generated.*args – Arguments to pass to the
NetworkCollection.createmethod.**kwargs – Keyword arguments to pass to the
NetworkCollection.createmethod.
- Returns:
A new temporary network.
Note
If any containers are connected to the network when the context manager is exited, they will be disconnected.
- networks.connect(network: Network, obj: Container | ContainerService, **kwargs) AbstractContextManager[list[str]][source]¶
Temporarily connect a container to a network.
- Parameters:
network – The network to connect to.
obj – A container or a container service to connect to the network.
**kwargs – Keyword arguments to pass to the
Network.connectorsubclasses.ContainerService.connect()method.
- Returns:
A context manager that connect and disconnects the network and the object, and yields the aliases of the object within the network.
- networks.disconnecting(network: Network, *, remove: bool = False) AbstractContextManager[Network][source]¶
Get a context manager that when exited, disconnects the network from all containers, and optionally deletes the network.
- Parameters:
network – The network to disconnect.
remove – Whether to delete the network when the context manager is exited.
- Returns:
A context manager that disconnects the network from all containers, and yields the network.