← Back to DevBytes

Docker Networks: Bridge, Host, Overlay, Macvlan: Production Guide

Understanding Docker Networking

Docker networking is the subsystem that allows containers to communicate with each other, with the host, and with external networks. By default, Docker ships with several built-in network drivers—Bridge, Host, Overlay, and Macvlan—that cover everything from simple single‑host setups to complex multi‑host, production‑grade deployments. Each driver provides a different level of isolation, performance, and configuration flexibility.

Why Network Design Matters in Production

In a production environment, your network topology directly impacts:

Choosing the wrong driver can lead to port collisions, IP exhaustion, or containers that cannot reach critical backend services. The following sections dive deep into each driver, complete with production‑ready code examples and best practices.

Bridge Network

🚀 Deploy your AI agent in 10 minutes

Managed Hermes hosting. Zero DevOps. 100M tokens/mo included.

Try it free →

What is the Bridge Driver?

The bridge driver creates a private, internal virtual network on a single Docker host. Containers attached to the same bridge can communicate directly via IP address or container name (DNS), while traffic destined outside the host must be explicitly published via port mapping or routing.

Docker provides two bridge networks out‑of‑the‑box:

Production Use Cases

How to Use Bridge Networks

Always create a user‑defined bridge for production workloads. Below is a complete workflow.

# 1. Create a user-defined bridge network
docker network create \
  --driver bridge \
  --subnet 172.25.0.0/16 \
  --gateway 172.25.0.1 \
  --attachable \
  app_net

# 2. Run a database container, attached to the bridge
docker run -d \
  --name postgres \
  --network app_net \
  --ip 172.25.0.10 \
  -e POSTGRES_PASSWORD=secret \
  postgres:15

# 3. Run an application container that resolves 'postgres' via DNS
docker run -d \
  --name app \
  --network app_net \
  -p 8080:3000 \
  my-app-image:latest

# 4. Inspect the network to see connected containers
docker network inspect app_net

# 5. Dynamically connect an existing container to the bridge
docker network connect app_net existing_container

# 6. Remove a container from the bridge
docker network disconnect app_net existing_container

Best Practices for Bridge

Host Network

What is Host Networking?

When a container uses the host driver, it shares the host machine’s network namespace directly. The container does not get its own IP address; instead, all its network interfaces are the host’s. Ports opened by the container appear on the host’s IP without any NAT or port mapping overhead.

When to Use Host in Production

Using Host Network

# Run nginx directly on the host network (no port mapping needed)
docker run -d \
  --name nginx-host \
  --network host \
  -v /etc/nginx/conf.d:/etc/nginx/conf.d:ro \
  nginx:latest

# Verify it's listening on the host's port 80
curl http://localhost:80

Because there is no network isolation, any port conflict with host services will cause the container to fail to bind. The container’s entire network stack (iptables, routing table, interfaces) is identical to the host’s.

Best Practices and Caveats

Overlay Network

Understanding Overlay Networks

Overlay networks extend Docker networking across multiple hosts, typically in a Docker Swarm cluster. They use VXLAN encapsulation to tunnel container traffic over physical networks, making containers on different nodes appear as if they are on the same flat network. Overlay networks support encryption (IPSec) and can be created as attachable for standalone containers or used natively by Swarm services.

Production Scenarios

Setting Up Overlay Networks

First, initialize a Swarm (or join an existing one). Then create an overlay network and deploy services.

# On the manager node, init the swarm
docker swarm init --advertise-addr 192.168.1.100

# Create an attachable overlay network (works for both services and standalone containers)
docker network create \
  --driver overlay \
  --attachable \
  --subnet 10.0.9.0/24 \
  --gateway 10.0.9.1 \
  --opt encrypted \
  backend_overlay

# Deploy a Swarm service attached to the overlay
docker service create \
  --name api \
  --network backend_overlay \
  --replicas 3 \
  -p 8000:8000 \
  my-api:latest

# Run a standalone container on any node and attach it to the overlay
docker run -d \
  --name debug-tool \
  --network backend_overlay \
  alpine/socat

Swarm services automatically get load‑balancing and service discovery via the overlay’s internal DNS. The --opt encrypted flag enables automatic IPSec encryption of all VXLAN traffic between nodes.

Overlay Network Best Practices

Macvlan Network

What is Macvlan?

Macvlan assigns a unique MAC address to each container, making it appear as a separate physical device on the network. Containers get their own IP addresses directly from the physical subnet, with no NAT or port mapping. They can communicate at Layer 2 with other physical machines and legacy systems that require direct MAC‑based visibility.

Macvlan Modes and Production Use Cases

How to Deploy Macvlan Networks

# 1. Create a macvlan network in bridge mode (no VLAN tag)
docker network create \
  --driver macvlan \
  --subnet 192.168.1.0/24 \
  --gateway 192.168.1.1 \
  --ip-range 192.168.1.200/29 \
  -o parent=eth0 \
  macvlan_net

# 2. Run a container with a static IP from the physical subnet
docker run -d \
  --name legacy_app \
  --network macvlan_net \
  --ip 192.168.1.201 \
  my-legacy-app:latest

# 3. Create an 802.1q trunk macvlan for VLAN 10
docker network create \
  --driver macvlan \
  --subnet 10.10.10.0/24 \
  --gateway 10.10.10.1 \
  -o parent=eth0.10 \
  vlan10_net

# 4. Run a container on VLAN 10
docker run -d \
  --name vlan_app \
  --network vlan10_net \
  --ip 10.10.10.50 \
  my-app-vlan:latest

The parent interface must exist on the host and be up. For VLAN trunking, create the sub‑interface (eth0.10) before creating the network, or use the macvlan driver with -o parent=eth0 -o vlan=10 (driver‑level VLAN tagging where supported).

Macvlan Production Best Practices

Network Comparison and Decision Framework

The table below summarises when each driver fits best. Use it as a quick reference when designing your production architecture.

Conclusion

Choosing the right Docker network driver is a foundational decision that affects security, performance, and operational complexity. In production, lean towards user‑defined bridge for single‑host isolation, overlay for multi‑host microservices, and reserve host and macvlan for the specialised cases where their unique characteristics are genuinely required. Always plan IP spaces ahead, encrypt inter‑node traffic, and document your network topology alongside your container orchestration configuration. A deliberate network strategy turns Docker from a simple container runtime into a robust, production‑grade platform.

🚀 Need a reliable AI agent for your project?

Deploy Hermes Agent in 10 minutes. Managed hosting, zero DevOps.

Get Started — $23.99/mo
← Back to all articles