Docker Compose — Default Network
When you run docker compose up, Compose automatically creates a default network for your project. Every service joins this network and can reach other services by name.
How It Works
┌──────────────────────────────────────┐
│ Project: myapp │
│ Network: myapp_default (bridge) │
│ │
│ ┌────────┐ ┌────────┐ ┌───────┐ │
│ │ web │ │ api │ │ db │ │
│ └───┬────┘ └───┬────┘ └───┬───┘ │
│ │ │ │ │
│ └───────────┴────────────┘ │
│ DNS resolution │
└──────────────────────────────────────┘
The network name is derived from your project directory name plus _default.
Compose File
services:
web:
image: nginx:alpine
ports:
- "80:80"
api:
image: node:20-alpine
command: node server.js
db:
image: postgres:16
No networks: key needed — Compose handles it.
Verify the Network
docker compose up -d
docker network ls
Expected output:
NETWORK ID NAME DRIVER SCOPE
a1b2c3d4e5f6 myapp_default bridge local
Service-to-Service Communication
From the web container you can reach api by name:
docker compose exec web ping api
PING api (172.20.0.3): 56 data bytes
64 bytes from 172.20.0.3: seq=0 ttl=64 time=0.123 ms
Inspect the Network
docker network inspect myapp_default
Key output:
{
"Name": "myapp_default",
"Driver": "bridge",
"Containers": {
"abc123": { "Name": "myapp-web-1", "IPv4Address": "172.20.0.2/16" },
"def456": { "Name": "myapp-api-1", "IPv4Address": "172.20.0.3/16" },
"ghi789": { "Name": "myapp-db-1", "IPv4Address": "172.20.0.4/16" }
}
}
Network Lifecycle
| Action | Network Behavior |
|---|---|
docker compose up |
Creates network if missing |
docker compose down |
Removes the network |
docker compose down -v |
Removes network + volumes |
docker compose stop |
Keeps the network |
Real-World Analogy
Think of the default network as an office LAN — every device on the same floor can find each other by hostname, no special configuration needed.
Summary
| Aspect | Detail |
|---|---|
| Created automatically | Yes, on docker compose up |
| Naming convention | <project>_default |
| Driver | bridge (default) |
| Service discovery | By service name (DNS) |
| Removed on | docker compose down |
Quick Reference
| Item | Detail |
|---|---|
| Auto-created | Yes, by docker compose up |
| Name pattern | projectname_default |
| DNS | Services reachable by service name |
| Inspect | docker network inspect |
| Lifecycle | Created on up, removed on down |