🌐 Network Management
Docker Network Modes
| Network Mode | Description | Use Case |
|---|---|---|
| bridge (default) | Containers have their own IP, communicate via virtual bridge | Most scenarios |
| host | Container uses the host's network directly | High-performance networking |
| none | No network | Security-sensitive offline tasks |
| overlay | Cross-host container communication | Docker Swarm clusters |
bash
# List all networks
docker network ls
NETWORK ID NAME DRIVER SCOPE
a1b2c3d4e5f6 bridge bridge local
f6e5d4c3b2a1 host host local
1a2b3c4d5e6f none null local
# Create a custom network
docker network create my-network
# Run containers in a custom network
docker run -d --name app1 --network my-network nginx
docker run -d --name app2 --network my-network nginx
# Containers can communicate by name!
docker exec app1 ping app2
PING app2 (172.18.0.3): 56 data bytes
64 bytes from 172.18.0.3: seq=0 ttl=64 time=0.089 ms📝 Note: 📝 The magic of custom networks: in a custom network, containers can reach each other using container names as domain names — no need to remember IP addresses! The default bridge network doesn't support this.