'How to remove network with docker sdk for python?

I am using docker sdk for python.

I am creating a network like so

    try:
        client.networks.create(name=network_name, check_duplicate=True)
    except docker.errors.APIError as ex:
        print(f"not recreating existing docker network: '{network_name}'")
        pass

which works fine.

I want to delete this network.

I am trying like so

def remove_docker_network(network_name: str, client: docker.client.DockerClient):
    try:
        client.networks.prune(filters={"name": network_name})
    except docker.errors.APIError as ex:
        print(f"not removing non existing docker network: '{network_name}'")
        pass

but network remains.

Doc only shows prune. There is no rm.

How to do it correctly?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source