When you first run a Docker container, it feels simple you just docker run and it works. But the moment you need containers to talk to each other, or to the outside world, things get tricky. Do you use bridge, host, overlay, or even macvlan? What’s the difference, and when should you pick each one?
This is one of the most confusing but critical parts of Docker. In this guide, we’ll break down the major Docker networking drivers Bridge, Host, Overlay, and Macvlan and explain them with clear examples and use cases that actually happen in real projects.
Bridge Network: The Default Choice
When you run a container without specifying anything, Docker puts it on a bridge network. Think of this as a private virtual switch inside your host machine. Containers on the same bridge can talk to each other using container names or IP addresses.
Example
Create a custom bridge network:
docker network create my_bridge
Run two containers on it:
docker run -dit --name app1 --network my_bridge busybox docker run -dit --name app2 --network my_bridge busybox
Now you can ping app2 from inside app1 because they’re on the same network.
When to Use Bridge
- Single-host setups.
- Simple microservices on one server.
- Local development environments.
Host Network: Sharing the Host’s Stack
The host network removes the isolation between the container and the host. That means your container shares the host’s IP address and networking stack.
Example
docker run -dit --network host nginx
Now, Nginx will run directly on your host’s IP at port 80 no port mapping needed.
When to Use Host
- High-performance networking is required (e.g., real-time apps).
- You want fewer hops (no NAT translation).
- Running monitoring tools like Prometheus node exporters.
Limitation: You lose isolation. If the container binds port 80, the host can’t use it.
Overlay Network: Multi-Host Magic
Bridge and host networks only work on a single machine. But what if you want containers across multiple hosts to communicate? That’s where overlay networks come in.
Overlay networks use VXLAN under the hood to create a virtual network spanning multiple hosts. This is essential for Docker Swarm or Kubernetes.
Example with Docker Swarm
- Initialize Swarm:
docker swarm init - Create an overlay network:
docker network create -d overlay my_overlay - Deploy services:
docker service create --name web --network my_overlay nginx docker service create --name api --network my_overlay busybox
Now, containers on different nodes in the cluster can communicate securely as if they were on the same machine.
When to Use Overlay
- Multi-host setups.
- Microservices in a Swarm or Kubernetes cluster.
- When you need service discovery across nodes.
Macvlan Network: Giving Containers Their Own IP
Sometimes you want containers to appear as physical devices on your LAN, with their own IP addresses. That’s where macvlan comes in. It assigns each container a unique MAC and IP on the local network.
Example
docker network create -d macvlan \ --subnet=192.168.1.0/24 \ --gateway=192.168.1.1 \ -o parent=eth0 my_macvlan
Then run a container:
docker run -dit --network my_macvlan --name my_container busybox
Now my_container has its own IP on your LAN (say 192.168.1.50), just like a real machine.
When to Use Macvlan
- When you need containers to be directly reachable on the physical network.
- Legacy applications that expect “real” IP addresses.
- Scenarios where you need network separation (e.g., PCI compliance).
Limitation: Macvlan is trickier to set up and can cause issues with host-to-container communication.
Choosing the Right Network
Here’s a quick way to think about it:
- Bridge: Good for local dev and simple apps on one machine.
- Host: Good for performance, but loses isolation.
- Overlay: Good for clusters and multi-host communication.
- Macvlan: Good when you need containers to behave like separate machines.
Real-World Scenarios
- Local Development
- Use a bridge network so your app, database, and cache can talk easily.
- High-Performance Services
- Use host network for applications like load balancers (HAProxy, Nginx) to cut down on latency.
- Distributed Applications
- Use overlay network in a Docker Swarm or Kubernetes cluster where services run across multiple nodes.
- Legacy Integration
- Use macvlan when migrating an old system that expects unique IPs for each service.
Docker networking is one of those things you can’t avoid as soon as your app moves beyond “hello world.” Bridge, host, overlay, and macvlan aren’t just theory they solve very real problems in DevOps.
- Bridge keeps things simple on a single host.
- Host gives raw performance.
- Overlay connects services across machines.
- Macvlan integrates containers directly into your LAN.
Mastering these will not only make you a stronger developer but also prepare you for interview questions where employers want to see if you can design networks for real-world distributed systems.






