Networks

class aiodocker.networks.DockerNetworks(docker)[source]
async create(config: dict[str, Any]) DockerNetwork[source]
async get(net_specs: str) DockerNetwork[source]
async list(*, filters: Mapping[str, str | Sequence[str]] | None = None) list[dict[str, Any]][source]

Return a list of networks

Parameters:

filters – a dict with a list of filters

Available filters:

dangling=<boolean> driver=<driver-name> id=<network-id> label=<key> or label=<key>=<value> of a network label. name=<network-name> scope=[“swarm”|”global”|”local”] type=[“custom”|”builtin”]

async prune(*, filters: Mapping[str, Any] | None = None) dict[str, Any][source]

Delete unused networks

Parameters:

filters – Filter expressions to limit which networks are pruned. Available filters: - until: Only remove networks created before given timestamp - label: Only remove networks with (or without, if label!=<key> is used) the specified labels

Returns:

Dictionary containing information about deleted networks

class aiodocker.networks.DockerNetwork(docker, id_)[source]
async connect(config: dict[str, Any]) None[source]
async delete() bool[source]
async disconnect(config: dict[str, Any]) None[source]
async show() dict[str, Any][source]

Example

Create a network

import asyncio
import aiodocker

async def create_network():
    docker = aiodocker.Docker()
    network_config = {
        "Name": "isolated_nw",
        "Driver": "bridge",
        "EnableIPv6": False,
        "IPAM": {
            "Driver": "default"
        }
    }
    network = await docker.networks.create(config=network_config)
    print(network)
    await docker.close()

if __name__ == "__main__":
    asyncio.run(create_network())