🌐 Docker Networking Visualizer

Bridge, host, overlay, macvlan — architecture diagrams and decision guides for every network driver.

Docker Networking Overview

Docker networking enables containers to communicate with each other, the Docker host, and external networks. Docker uses the Container Network Model (CNM) to standardize networking across different environments.

Key Networking Concepts

Network Namespaces

Each container runs in its own network namespace, providing isolation of network stack, IP addresses, and routing tables.

Virtual Ethernet (veth) Pairs

Docker uses veth pairs to connect containers to networks. One end is inside the container, the other connects to the host.

Bridges

Act as virtual switches that forward traffic between containers and the host network.

Port Mapping

Containers expose specific ports to the host using port mapping (-p flag), enabling external access.

Service Discovery

Containers on the same network can discover each other using container names via built-in DNS.

Network Address Translation (NAT)

Docker uses NAT to route traffic between containers and external networks through the host.

📹 Network Visualization Videos

Docker Network Drivers

Driver Scope Use Case Default
bridge Single host Local container-to-container communication ✓ Yes
host Single host No network isolation, direct host network access ✗ No
overlay Multi-host Docker Swarm, distributed applications ✗ No
macvlan Single host Legacy apps, direct physical network integration ✗ No
ipvlan Single host Advanced IP control, high-density environments ✗ No
none Single host Complete network isolation, manual configuration ✗ No

Common Docker Network Commands

# List all networks
docker network ls

# Inspect a network
docker network inspect bridge

# Create a custom network
docker network create my-network

# Connect container to network
docker network connect my-network container-name

# Disconnect container from network
docker network disconnect my-network container-name

# Remove a network
docker network rm my-network

Bridge Network

The bridge network is Docker's default networking mode. It creates a private internal network on the host, allowing containers on the same bridge to communicate while providing isolation from the host and external networks.

Key Feature: Automatic service discovery via DNS - containers can reach each other using container names.

📹 Video & Architecture Diagram

Bridge Networking Video

Architecture Diagram

External Network (Internet)
↓
Docker Host (eth0)
↓
docker0 Bridge (172.17.0.1)
Virtual Switch + NAT
↓
Container 1
eth0: 172.17.0.2
veth pair
Container 2
eth0: 172.17.0.3
veth pair
Container 3
eth0: 172.17.0.4
veth pair

How It Works

1. Bridge Creation

Docker creates a virtual bridge (docker0) on the host, acting as a software switch.

2. Virtual Ethernet Pairs

Each container gets a veth pair - one end inside container (eth0), other end attached to docker0.

3. IP Assignment

Containers receive private IPs from the bridge subnet (default: 172.17.0.0/16).

4. Internal Communication

Containers communicate directly via the bridge using IPs or container names.

5. NAT for External Access

Docker uses iptables NAT rules to route external traffic through the host.

6. Port Publishing

Use -p flag to map container ports to host ports for external access.

Packet Flow Example

Container A → Container B:

Container A
eth0
→ veth-A
(host)
→ docker0
bridge
→ veth-B
(host)
→ Container B
eth0

✓ Advantages

  • Easy to set up - default configuration
  • Automatic network isolation
  • Built-in DNS service discovery
  • Suitable for single-host deployments
  • Low overhead and good performance

✗ Limitations

  • Limited to single host
  • Requires port mapping for external access
  • No multi-host service discovery
  • NAT introduces slight latency
  • Not suitable for distributed applications

Usage Examples

# Use default bridge
docker run -d --name nginx nginx

# Create custom bridge network
docker network create --driver bridge my-bridge

# Run container on custom bridge
docker run -d --name app --network my-bridge nginx

# Publish ports to host
docker run -d -p 8080:80 --name web nginx

# Inspect bridge network
docker network inspect bridge

Host Network

The host network mode removes network isolation between the container and the Docker host. Containers share the host's network stack directly, using the same IP addresses and ports.

Warning: No network isolation means containers can access all host network interfaces and ports. Use carefully!

📹 Video & Architecture Diagram

Host Networking Video

Architecture Diagram

External Network (Internet)
↓
Docker Host Network Stack
(eth0, IP addresses, routing table)
↓
Container 1
Uses host network
No isolation
Container 2
Uses host network
No isolation
Containers share host's IP, ports, and network interfaces

How It Works

1. No Network Namespace

Container doesn't get its own network namespace - uses host's directly.

2. Direct Host Access

Container sees all host network interfaces (eth0, lo, etc.) as if running on host.

3. No Port Mapping

-p flag has no effect. Container listens on host ports directly.

4. Same IP Address

Container uses the host's IP address for all network operations.

5. Performance Benefits

Eliminates network virtualization overhead - best performance.

6. Port Conflicts

Multiple containers can't bind to the same port - need to coordinate.

✓ Advantages

  • Maximum network performance
  • No NAT overhead or latency
  • Direct access to host network services
  • Simpler configuration for some scenarios
  • Suitable for network monitoring tools

✗ Limitations

  • No network isolation or security
  • Port conflicts between containers
  • Less portable across environments
  • Not available on Docker Desktop for Mac/Windows
  • Can't use with Docker Swarm services

Use Cases

Performance-Critical Apps

Applications requiring maximum network throughput with minimal latency.

Network Monitoring

Tools that need to monitor all network traffic on the host.

System Services

Services that need to integrate tightly with host networking (VPNs, proxies).

Development Testing

Quick testing where isolation isn't needed and performance matters.

Usage Examples

# Run container with host network
docker run -d --network host --name nginx nginx

# Container listens on host's port 80 directly
# No -p flag needed or allowed

# Check container network mode
docker inspect nginx | grep NetworkMode

# Example: Network monitoring tool
docker run -d --network host --name monitor nicolaka/netshoot

Overlay Network

Overlay networks enable multi-host networking for Docker Swarm and distributed applications. They create a virtual network spanning multiple Docker hosts, allowing seamless container communication across hosts.

Key Feature: Built-in encryption support for secure communication between hosts and automatic service discovery across the cluster.

📹 Video & Architecture Diagram

Overlay Networking Video

Architecture Diagram

Docker Host 1
IP: 192.168.1.10
↓
Overlay Network
ingress (VXLAN)
↓
Container A
10.0.9.2
Container B
10.0.9.3
↔
Docker Host 2
IP: 192.168.1.11
↓
Overlay Network
ingress (VXLAN)
↓
Container C
10.0.9.4
Container D
10.0.9.5
Containers communicate across hosts transparently via overlay network

How It Works

1. VXLAN Encapsulation

Uses VXLAN (Virtual Extensible LAN) to encapsulate container traffic over the physical network.

2. Multi-Host Spanning

Creates a single logical network across multiple Docker hosts in a swarm.

3. Automatic Routing

Docker handles routing packets between hosts transparently.

4. Service Discovery

Built-in DNS allows containers to discover services across the entire cluster.

5. Encryption Support

Optional IPsec encryption for secure communication between hosts.

6. Load Balancing

Ingress network provides load balancing for published service ports.

Required Ports for Overlay Network

Port Protocol Purpose
2377 TCP Cluster management communications
7946 TCP & UDP Container network discovery
4789 UDP Overlay network traffic (VXLAN)

✓ Advantages

  • Multi-host container communication
  • Built-in service discovery across cluster
  • Automatic load balancing (ingress)
  • Optional encryption for security
  • Seamless with Docker Swarm
  • Scalable for distributed applications

✗ Limitations

  • Requires Docker Swarm mode
  • More complex setup than bridge
  • Slight performance overhead from encapsulation
  • Requires open ports between hosts
  • Encryption adds additional overhead

Usage Examples

# Initialize Docker Swarm
docker swarm init

# Create overlay network
docker network create --driver overlay my-overlay

# Create service on overlay network
docker service create --name web --network my-overlay --replicas 3 nginx

# Create overlay with encryption
docker network create --driver overlay --opt encrypted my-secure-overlay

# List overlay networks
docker network ls --filter driver=overlay

# Inspect overlay network
docker network inspect my-overlay

Use Cases

Docker Swarm Clusters

Essential for multi-node Docker Swarm deployments.

Microservices Architecture

Services distributed across multiple hosts need to communicate.

High Availability

Distribute containers across hosts for fault tolerance.

Secure Multi-Host Apps

Applications requiring encrypted communication between hosts.

Macvlan Network

Macvlan networks assign unique MAC addresses to containers, making them appear as physical devices on the network. This allows containers to be directly connected to the physical network without NAT or port mapping.

Use Case: Legacy applications that expect physical network interfaces or integration with network appliances requiring MAC addresses.

📹 Video & Architecture Diagram

Macvlan Networking Video

Architecture Diagram

Physical Network
192.168.1.0/24
↓
Docker Host
Physical NIC (eth0)
↓
Container 1
MAC: 02:42:ac:11:00:02
IP: 192.168.1.100
Appears as physical device
Container 2
MAC: 02:42:ac:11:00:03
IP: 192.168.1.101
Appears as physical device

How It Works

1. Unique MAC Address

Each container receives its own MAC address, separate from the host.

2. Physical Network Integration

Containers appear as physical devices on the network to external systems.

3. Direct Network Access

No NAT or port mapping - containers have direct IPs on physical network.

4. VLAN Support

Can assign containers to specific VLANs (802.1Q tagging).

5. No Docker Bridge

Bypasses Docker's virtual bridge entirely for maximum performance.

6. Parent Interface

Macvlan networks must be bound to a physical host interface.

✓ Advantages

  • Containers appear as physical devices
  • No NAT overhead - better performance
  • Direct physical network integration
  • VLAN support for network segmentation
  • Works with legacy network infrastructure

✗ Limitations

  • Requires promiscuous mode on host NIC
  • May not work in cloud environments
  • More complex IP management
  • Limited by MAC address table size on switches
  • Containers can't reach host by default

Macvlan Modes

Bridge Mode (Default)

Containers on same host can communicate. Traffic to external network goes through parent interface.

802.1q Trunk Mode

VLAN tagging support - assign containers to specific VLANs on trunked interface.

Usage Examples

# Create macvlan network
docker network create -d macvlan \
--subnet=192.168.1.0/24 \
--gateway=192.168.1.1 \
-o parent=eth0 my-macvlan

# Run container on macvlan
docker run -d --network my-macvlan --ip=192.168.1.100 --name web nginx

# Create macvlan with VLAN (802.1q)
docker network create -d macvlan \
--subnet=192.168.10.0/24 \
-o parent=eth0.10 vlan10

# Inspect macvlan network
docker network inspect my-macvlan

IPvlan Alternative

IPvlan is similar to Macvlan but uses the parent interface's MAC address instead of assigning unique MACs. This is more efficient for high-density environments where MAC address table limits are a concern.

Network Types Comparison

Choose the right network type based on your deployment requirements, performance needs, and infrastructure constraints.

Feature Comparison Matrix

Feature Bridge Host Overlay Macvlan
Scope Single host Single host Multi-host Single host
Network Isolation ✓ Yes ✗ No ✓ Yes ✓ Yes
Performance Good Excellent Good (overhead) Excellent
Service Discovery ✓ DNS ✗ Manual ✓ DNS ✗ Manual
Port Mapping Required ✓ Yes ✗ No Managed ✗ No
NAT Used ✓ Yes ✗ No ✓ Yes ✗ No
Default Network ✓ Yes ✗ No ✗ No ✗ No
Setup Complexity Simple Very Simple Complex Moderate
Security Good Low Excellent Good
Cloud Compatible ✓ Yes ✓ Yes ✓ Yes Limited

When to Use Each Network Type

Use Bridge When:

  • Single-host deployments
  • Development and testing
  • Need container isolation
  • Default choice for most apps
  • Simple microservices on one host

Use Host When:

  • Maximum performance needed
  • Network monitoring tools
  • Direct host network access required
  • No isolation concerns
  • Single container per service

Use Overlay When:

  • Docker Swarm deployments
  • Multi-host communication needed
  • Distributed applications
  • High availability setups
  • Need encryption between hosts

Use Macvlan When:

  • Legacy app integration
  • Need physical network presence
  • VLAN requirements
  • Network appliance integration
  • MAC address visibility needed

Performance Considerations

Network Performance Ranking (Best to Lowest):

1. Host
(No overhead)
→ 2. Macvlan
(Direct access)
→ 3. Bridge
(NAT overhead)
→ 4. Overlay
(Encapsulation)

Security Comparison

Most Secure

  • Overlay - Encryption support, isolated multi-host
  • Bridge - Network isolation, controlled exposure
  • Macvlan - Physical network level isolation

Least Secure

  • Host - No isolation, full network access
  • None - Complete isolation (no network at all)

Decision Flow

Question 1: Do you need multi-host communication?
YES → Use OVERLAY
NO → Continue to Question 2

Question 2: Do you need maximum performance?
YES → Use HOST (if isolation not needed) or MACVLAN
NO → Continue to Question 3

Question 3: Do you need physical network integration?
YES → Use MACVLAN
NO → Use BRIDGE (default choice)