Skip to content

🌐 Network Management

Docker Network Modes

Network ModeDescriptionUse Case
bridge (default)Containers have their own IP, communicate via virtual bridgeMost scenarios
hostContainer uses the host's network directlyHigh-performance networking
noneNo networkSecurity-sensitive offline tasks
overlayCross-host container communicationDocker 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.