TL;DR: Disconnect the containers first, then remove the network. `docker network inspect mynet` shows what is attached; `docker network disconnect mynet [container]` each one (or stop/remove the containers), then `docker network rm mynet` succeeds. The daemon will not delete a network with live endpoints.

## The error

```text
error while removing network: network mynet id xyz has active endpoints
```

## Fix it

1. List the attached containers:
   `docker network inspect mynet --format '{{range .Containers}}{{.Name}} {{end}}'`
   Expected: one or more container names.
2. Disconnect each (or stop/remove the containers if done with them):
   `docker network disconnect mynet [container]`
   Expected: no output.
3. Remove the network:
   `docker network rm mynet`
   Expected: prints the network name.

## When this applies
- Cleaning up networks while containers still reference them
- `docker network prune` skipping networks for the same reason

## When this does NOT apply
- "network not found" (already gone; nothing to do)
- Built-in networks (bridge/host/none cannot be removed this way anyway)

## Versions
All Docker versions.

## Why it happens
A network with attached endpoints still has veth interfaces and iptables rules referencing it. The daemon refuses removal to avoid stranding container networking in a half-torn-down state.

## Edge cases
- Containers in "created" (never started) state still count as endpoints; inspect shows them.
- Force-removing a container (`docker rm -f`) auto-disconnects it from all networks.
- If a container is stuck and cannot be removed, restarting the daemon usually clears the phantom endpoint.
