Docker Network Types
Docker provides several network drivers, each suited to different use cases. Understanding them is key to designing multi-container applications.
Bridge Network (Default)
Containers on the same bridge network can communicate by container name. This is the default for standalone containers.
# Create a custom bridge network
docker network create myapp-net
# Run containers on the same network
docker run -d --name web --network myapp-net nginx
docker run -d --name api --network myapp-net node:20
# web can reach api by name: http://api:3000Host Network
Removes network isolation — the container shares the host network stack directly. Useful for performance-sensitive applications.
docker run -d --network host nginx
# Nginx is now accessible on host port 80 directlyLimitations: no port mapping (-p is ignored), potential port conflicts.
Overlay Network
Connects containers across multiple Docker hosts (Swarm mode). Traffic is encrypted and routed through a VXLAN tunnel.
# Initialize Swarm
docker swarm init
# Create overlay network
docker network create --driver overlay --attachable myoverlay
# Deploy services on the overlay
docker service create --name web --network myoverlay nginxNone Network
docker run --network none alpine
# Container has no external connectivity — only loopbackInspecting Networks
docker network ls
docker network inspect myapp-netCustom Subnet Configuration
docker network create --subnet=172.20.0.0/16 --gateway=172.20.0.1 custom-netDNS Resolution
Custom bridge and overlay networks include an embedded DNS server. Containers resolve each other by name or network alias. The default bridge network does not provide DNS resolution — use custom networks instead.