← All cheatsheets
Docker Networking Cheatsheet
Connect containers with bridge, overlay, and host networks. Expose ports and manage DNS.
What it is
Docker networking allows containers to communicate with each other and the outside world. Docker provides multiple network drivers: bridge (default), host, overlay (Swarm), macvlan, and none.
Installation
Built into Docker Engine. No additional installation needed.
Quick start
Create a custom bridge network.
Connect a container to a network.
List all networks.
Show network details and connected containers.
Common commands
| Task | Command | Description |
|---|---|---|
| Create network | docker network create <name> |
Create a new bridge network. |
| List networks | docker network ls |
Show all Docker networks. |
| Inspect network | docker network inspect <name> |
Show containers, IPAM config, drivers. |
| Connect container | docker network connect <net> <container> |
Attach a running container to a network. |
| Disconnect | docker network disconnect <net> <container> |
Remove a container from a network. |
| Remove network | docker network rm <name> |
Delete a network (no active containers). |
| Prune networks | docker network prune |
Remove all unused networks. |
| Publish port | docker run -p 8080:80 nginx |
Map host port 8080 to container port 80. |
Real-world examples
Create an isolated network for a multi-container app
docker network create appnet
docker run -d --name db --network appnet postgres:16
docker run -d --name api --network appnet -p 3000:3000 myapi
Inspect which containers are on a network
docker network inspect appnet --format "{{json .Containers}}"
Override DNS search in Compose
services:
api:
networks:
- appnet
dns:
- 8.8.8.8
networks:
appnet:
Best practices
- Always create custom networks for multi-container apps instead of using the default bridge.
- Use container names as hostnames within the same network — Docker provides automatic DNS.
- Use
--network hostonly when needed (Linux only); it removes network isolation. - Remove unused networks with
docker network pruneto keep the host tidy.
Related cheatsheets
Last reviewed: 2026-06-15