Docker Compose — Network Drivers
Docker supports multiple network drivers. The driver you choose determines how containers communicate.
Driver Comparison
| Driver | Use Case | Scope |
|---|---|---|
bridge |
Single-host container networking (default) | Local |
host |
Container shares host network stack | Local |
overlay |
Multi-host (Swarm / Kubernetes) | Swarm |
macvlan |
Container gets real MAC address on LAN | Local |
none |
No networking at all | Local |
Bridge Driver (Default)
networks:
app-net:
driver: bridge
This is the most common driver. Containers get their own IP on an isolated bridge network.
Host Driver
services:
web:
image: nginx:alpine
network_mode: "host"
The container shares the host’s network directly. No port mapping needed — the container binds directly to host ports.
Warning: network_mode: "host" only works on Linux. On macOS/Windows, Docker Desktop runs in a VM.
Overlay Driver
networks:
swarm-net:
driver: overlay
attachable: true
Used in Docker Swarm for multi-host communication. The attachable flag lets standalone containers join.
Macvlan Driver
networks:
lan:
driver: macvlan
driver_opts:
parent: eth0
ipam:
config:
- subnet: 192.168.1.0/24
gateway: 192.168.1.1
Gives each container a unique MAC address on the physical network — useful for legacy apps that expect direct LAN access.
Network Mode Shortcut
Instead of defining networks, you can set network_mode directly:
services:
debug:
image: alpine
network_mode: "host" # Use host networking
isolated:
image: alpine
network_mode: "none" # No network at all
sidecar:
image: alpine
network_mode: "service:web" # Share network with 'web'
Choosing the Right Driver
Need multi-host?
├── Yes → overlay
└── No
├── Need real LAN address? → macvlan
├── Need max performance? → host
├── Need isolation? → bridge (default)
└── Need no network? → none
Summary
| Driver | Isolation | Multi-Host | Performance |
|---|---|---|---|
| bridge | High | No | Good |
| host | None | No | Best |
| overlay | High | Yes | Good |
| macvlan | Medium | No | Good |
| none | Total | No | N/A |
Quick Reference
| Item | Detail |
|---|---|
| bridge | Default, isolated container network |
| host | Shares host network stack |
| overlay | Multi-host (Swarm) |
| macvlan | Real MAC address on LAN |
| none | Completely isolated |
| network_mode | Shortcut for host/none/service |