
Docker Networking is one of the most confusing aspects for beginners. Why can some containers communicate while others can't? Why can't a container reach the internet? Why does a mapped port work from the host but not from another container? This guide covers every Docker Network driver with practical examples to help you choose the right one for each scenario.
How Docker Networking Works
Docker has its own network stack separate from the host. Each container can connect to multiple networks simultaneously. Docker manages this through Network Drivers that define communication behavior.
Key principle: Containers on the same network can communicate directly using container names (automatic DNS). Containers on different networks must use port mapping or be connected to a shared network.
Docker Network Driver Types
Bridge
Virtual private network on a single host. Containers in the same group can communicate. Most commonly used.
Host
Container shares the host's network stack directly. No NAT, highest throughput, but no isolation.
Overlay
Connects containers across multiple hosts. Used with Docker Swarm or Kubernetes.
Macvlan
Container gets a real IP on the LAN — appears as a physical machine. Ideal for legacy network integration.
Bridge Network — The Default
When you run a container without specifying a network, Docker uses the default bridge network automatically. However, this default bridge does not support DNS resolution between containers. Use a user-defined bridge instead.
Benefits of User-defined Bridge
- Automatic DNS — containers resolve each other by name (no IP needed)
- Isolation — separate networks per application
- Runtime flexibility — connect/disconnect containers at runtime
- Control — define custom subnet and gateway
Host Network — Maximum Performance
The container uses the host's network interface directly with no virtual network layer, resulting in lowest latency and highest throughput. Ideal for monitoring agents or network-intensive applications.
Note: Host networking only works on Linux. On Mac/Windows (Docker Desktop), performance is similar to bridge because there's still a VM layer underneath.
Overlay Network — Across Multiple Hosts
Used with Docker Swarm or Kubernetes so containers on different nodes communicate as if on the same network. Data is encapsulated using VXLAN protocol.
None Network — Complete Isolation
Container has no network interfaces at all (except loopback). Use for batch jobs that require no network, or when you need maximum isolation.
Docker Network Driver Comparison
| Driver | Use Case | DNS | Multi-host | Performance |
|---|---|---|---|---|
| bridge | Default, Local Dev, Single Host | ✅ (user-defined) | ❌ | Good |
| host | High Performance, Monitoring | Host DNS | ❌ | Best |
| overlay | Swarm, Multi-host | ✅ | ✅ | Good (VXLAN overhead) |
| macvlan | Legacy Network, Physical IP | ❌ | ❌ | Very good |
| none | Batch Job, Max Isolation | ❌ | ❌ | N/A |
Docker Compose and Networks
Docker Compose automatically creates a bridge network. All services in the same Compose file share that network by default.
Common Network Commands
Troubleshooting: Containers Cannot Communicate
- Different networks: Use
docker network inspectto confirm both containers are on the same network - Default bridge in use: Default bridge has no DNS — migrate to a user-defined bridge
- Host firewall: Check
iptablesorufwfor blocking rules - Port not exposed: Use
EXPOSEin Dockerfile or--exposeso other containers can reach the port
Securing Docker Networks on Your VPS
Correct network configuration is a critical part of hardening a Docker-based VPS. Follow these security best practices to minimize your attack surface:
- Use internal networks for databases: Set
internal: truein Compose to cut off internet access for containers that don't need it (MySQL, Redis, etc.) - Restrict port binding to localhost: Use
127.0.0.1:3306:3306instead of3306:3306to prevent the database port from being exposed to the internet - Only expose necessary ports: Expose only the ports that genuinely need external access
- Audit iptables regularly: Docker modifies iptables automatically — these rules can bypass ufw policies you've set at the OS level
Macvlan Network — Integrating Legacy Systems
Macvlan is the right choice when a container needs a real IP address on your LAN, making it appear as a separate physical machine. Common use cases include:
- Legacy applications with hardcoded IP requirements
- Applications that need multicast or broadcast traffic
- Network monitoring tools that require a real interface
- DHCP servers that must reside on the real LAN segment
Macvlan limitation: The host cannot communicate directly with containers on the same Macvlan network due to a Linux kernel restriction. You need to create a Macvlan sub-interface on the host to enable host-to-container traffic.
Docker Network Driver Selection Reference
Use this quick-reference table to choose the right network driver for each scenario:
| Scenario | Driver | Why |
|---|---|---|
| Web app + database on one VPS | User-defined Bridge | Automatic DNS, good isolation |
| Monitoring agent | Host | Needs direct access to host network stats |
| Microservices across multiple VPS nodes | Overlay | Transparent cross-node communication via Swarm |
| Legacy system requiring real LAN IP | Macvlan | Container gets a real IP on the physical network |
Scaling with Docker Swarm Overlay Networks
When a single VPS can no longer handle your workload, Docker Swarm lets you distribute containers across multiple nodes. Overlay networks connect them transparently regardless of which physical machine they run on:
Docker-Ready VPS from AsiaGB
AsiaGB VPS supports Docker and Docker Compose out of the box. Full root access to configure networking as needed. Starting at ฿500/month.
View VPS Plans