Docker Network Types
Docker supports multiple network drivers for different use cases.
Network Drivers
| Driver | Use Case |
|---|---|
| bridge | Default, container-to-container |
| host | Container uses host network |
| none | No networking |
| overlay | Multi-host (Swarm) |
| macvlan | Assign MAC address |
| ipvlan | Assign IP without MAC |
Bridge Network (Default)
# Create bridge network
docker network create my-bridge
# Run container on bridge
docker run -d --network my-bridge --name web nginx
# Containers can communicate by name
docker run -it --network my-bridge alpine ping web# In Compose
networks:
app-network:
driver: bridgeHost Network
Container shares host's network namespace.
# No port mapping needed - container uses host ports directly
docker run -d --network host nginx
# Port 80 is now accessible on host
curl localhost:80Best for:
- Maximum network performance
- When container needs host's network identity
- Avoiding NAT overhead
None Network
Container has no network access.
docker run -d --network none alpine sleep infinity
# Only loopback interface available
docker exec container ip addrOverlay Network (Swarm)
# Create overlay network (requires Swarm mode)
docker network create -d overlay my-overlay
# Services on overlay can communicate across hosts
docker service create --network my-overlay --name web nginxMacvlan Network
Container gets its own MAC address on physical network.
# Create macvlan network
docker network create -d macvlan \
--subnet=192.168.1.0/24 \
--gateway=192.168.1.1 \
-o parent=eth0 my-macvlan
# Container appears as physical device on LAN
docker run -d --network my-macvlan --ip 192.168.1.100 nginxNetwork Inspection
# List networks
docker network ls
# Inspect network
docker network inspect bridge
# View container networks
docker inspect --format='{{json .NetworkSettings.Networks}}' container
# Get container IP
docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' containerComparison
| Feature | Bridge | Host | Overlay |
|---|---|---|---|
| Isolation | Yes | No | Yes |
| Port mapping | Required | No | Required |
| Multi-host | No | No | Yes |
| Performance | Good | Best | Good |
| Complexity | Low | Low | Medium |
- docker
- networking
- bridge
- host
- overlay
- macvlan