A user-defined network is a bridge network you create and name. It isolates a group of containers and lets them find each other by name.
Default bridge | User-defined bridge | |
|---|---|---|
| Created by | Docker, at startup | You, with docker network create |
| Containers join | When started without --network | With --network NAME or docker network connect |
| Reach by IP | yes | yes |
| Reach by container name | no | yes |
| Isolation | Every unattached container shares it | Only containers you attach |
Create one
sh
docker network create shoptext
4097c88e92504fea9d3d3215462142695337a13dac694997b12db865f27a7eb4The default driver is bridge. Docker picks the next free subnet (172.18.0.0/16, 172.19.0.0/16, …). Pass --subnet 10.10.0.0/24 to choose one.
sh
docker network lstext
NETWORK ID NAME DRIVER SCOPE
6133d93a1424 bridge bridge local
d903b86f388c host host local
4f0bd8326f81 none null local
4097c88e9250 shop bridge localRun containers on it
sh
docker run -d --name catalog --network shop nginx:1.27
docker run -d --name sessions --network shop redis:7.4text
shop 172.18.0.0/16
┌──────────────────────────────────────┐
│ catalog 172.18.0.2 │
│ sessions 172.18.0.3 │
└──────────────────────────────────────┘
default bridge containers cannot reach theseAny container on shop can now use the names:
sh
docker run --rm --network shop alpine:3.20 wget -qO- http://catalogtext
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>See who is attached
docker network inspect shop prints the subnet under IPAM.Config and each container under Containers. A Go template keeps it short:
sh
docker network inspect --format '{{range .Containers}}{{.Name}} {{.IPv4Address}}{{println}}{{end}}' shoptext
catalog 172.18.0.2/16
sessions 172.18.0.3/16Remove networks
A network with attached containers cannot be removed:
sh
docker network rm shoptext
Error response from daemon: error while removing network: network shop id 4097c88e92504fea9d3d3215462142695337a13dac694997b12db865f27a7eb4 has active endpoints| Command | Removes |
|---|---|
docker network rm NAME | One network with no attached containers |
docker network prune | Every user-defined network no container uses (asks to confirm; -f skips) |
The three built-in networks (bridge, host, none) are never removed.