Docker Network Commands
These commands let you manage container networking. You can create, list, inspect, connect, disconnect, and remove networks. Networks allow containers to communicate with each other and with external systems in a secure, flexible way.
docker network → Manage networks
docker network create → Create a network
docker network ls → List networks
docker network inspect → Display detailed information on one or more networks
docker network connect → Connect a container to a network
docker network disconnect → Disconnect a container from a network
docker network rm → Remove one or more networks
docker network prune → Remove all unused networks
Docker Network
docker network → Manage networksUsage : docker networkDocker network create
docker network create → Create a networkUsage : docker network create [OPTIONS] NETWORK
Aliases : NADescription:
- Creates a new network for containers.
- Drivers:
bridge→ default, isolated to one Docker Engine.overlay→ spans multiple Docker hosts (requires Swarm mode).You can also use custom drivers. - If no driver is given, Docker makes a bridge network automatically (
docker0). - New containers connect to the default bridge unless you specify another network.
- Swarm overlay networks:By default, only swarm services can attach.Use
--attachableto also allow manually started containers. - Rules:Network names must be unique (Docker tries to detect conflicts, but you must avoid them).
- Limitations:Overlay networks use
/24blocks (max 256 IPs).For more IPs, usednsrrmode with a load balancer or multiple smaller overlay networks.

Docker network ls
docker network ls → List networksUsage : docker network ls [OPTIONS]
Aliases : dockert network listDescription:
- Lists all the networks known to the Docker Engine
daemon. - Includes local networks and those that span across multiple hosts in a Swarm cluster.

Docker network inspect
docker network inspect → Display detailed information on one or more networksUsage : docker network inspect [OPTIONS] NETWORK [NETWORK...]
Aliases : NADescription:
- Shows detailed information about one or more networks.
- By default, results are displayed as a JSON object but you can use formatting options to customize the output.

Docker network connect
docker network connect → Connect a container to a networkUsage : docker network connect [OPTIONS] NETWORK CONTAINER
Aliases : NADescription:
- You can specify the container by name or ID while connecting a container to a network.
- Once connected, the container can communicate with other containers in the same network.

Docker network disconnect
docker network connect → Connect a container to a networkUsage : docker network connect [OPTIONS] NETWORK CONTAINER
Aliases : NADescription:
- The container must be running to be disconnected while disconnecting a container from a network.

Docker network rm
docker network rm → Remove one or more networksUsage : docker network rm NETWORK [NETWORK...]
Aliases : docker network removeDescription:
- Removes one or more networks (by name or ID).
- To remove a network, you must first disconnect all containers using it.

Docker network prune
docker network prune → Remove all unused networksUsage : docker network prune [OPTIONS]
Aliases : NADescription:
- Removes all unused networks.
- Unused networks = those not referenced by any containers.

Follow for Engineering and Tech - Tips, Tricks, Roadmaps, Resources, Networking, Motivation, Guidance, and Cool Stuff ♥
