Skip to main content

Docker Networking Guide: Bridge, Overlay & Host Network Modes

Docker networking controls how containers communicate with each other and the outside world. Understanding the five network drivers and how Docker Compose creates networks is essential for designing reliable containerized applications.

✓ 5 network drivers ✓ Container DNS resolution ✓ Docker Compose networks ✓ Port mapping & inspection
Share this tool: X / Twitter LinkedIn
✓ 60,000+ developers use DevPlaybook ★★★★★ 4.8 / 5 on Gumroad ✓ MIT licensed · Instant download ✓ No login required

Related Products

on Gumroad

You Might Also Need

More Free Tools

Enjoying this tool? Get more like it.

Weekly developer tool guides, productivity playbooks & AI tricks. Free. No spam.

DevPlaybook Pro 7 days free

Unlock AI-Powered Dev Tools

  • ⚡ AI Code Review, Doc Generator & SQL Builder
  • ⚡ All premium templates & early access
  • ⚡ Member discounts on Gumroad products
Start Free Trial →

$9/mo after trial · Cancel anytime

Want the full toolkit?

Get DevPlaybook Pro

Every template, guide, boilerplate, and automation script in one bundle. 13 premium products — grab them all at once and save big.

$79
$241 separately Save $162 (67% off)
Get DevPlaybook Pro — $79 →

MIT licensed · Instant download · No subscription

See what's included → Browse all deals →

Docker Network Drivers Comparison

Driver Scope Isolation DNS Use case
bridgeSingle hostVirtual L2 subnetUser-defined onlyDefault for single-host apps
hostSingle hostNone (shares host network)Host DNSMax performance, monitoring
overlayMulti-hostVXLAN tunnelYes (Swarm services)Docker Swarm, multi-host
macvlanSingle hostPhysical MAC addressDHCP / staticLegacy apps, raw network access
noneN/AComplete isolationNoneBatch jobs, security-sensitive

Bridge Networking (Default)

Bridge is the default driver. Docker creates a virtual bridge interface (docker0) on the host. Each container in the network gets an IP from the bridge subnet (typically 172.17.0.0/16).

# Create a user-defined bridge network (enables container DNS)
docker network create --driver bridge myapp-network

# Run containers on the named network
docker run -d --name api --network myapp-network myapi:latest
docker run -d --name db --network myapp-network postgres:16

# From 'api' container, reach 'db' by name:
# psql -h db -U postgres   ← DNS resolves 'db' to container IP

# Port mapping: host:container
docker run -d -p 8080:80 --network myapp-network nginx
Default bridge limitation: The default docker0 bridge does not support container name DNS resolution. Always create named networks with docker network create.

Docker Compose Networking

Compose automatically creates a default bridge network for each project. Services communicate using their service names as DNS hostnames.

services:
  frontend:
    image: nginx
    ports:
      - "80:80"
    networks:
      - frontend-net

  api:
    image: myapi:latest
    networks:
      - frontend-net   # Reachable from frontend as 'api'
      - backend-net    # Reachable from db layer

  db:
    image: postgres:16
    networks:
      - backend-net    # Only accessible from api, NOT frontend

networks:
  frontend-net:
    driver: bridge
  backend-net:
    driver: bridge

This pattern isolates the database from the frontend — frontend cannot reach db because they share no common network. Defense in depth even within Docker.

Network Inspection Commands

# List all Docker networks
docker network ls

# Inspect a network (see containers, subnet, gateway)
docker network inspect myapp-network

# See which networks a container is connected to
docker inspect api --format '{{json .NetworkSettings.Networks}}'

# Connect a running container to another network
docker network connect backend-net api

# Disconnect
docker network disconnect frontend-net api

# Remove unused networks
docker network prune

Host Networking for Performance

Host networking removes Docker's NAT layer. The container uses the host's network stack directly. Zero port-mapping overhead — useful for high-performance services or network monitoring tools.

# Run with host networking (Linux only — not supported on Docker Desktop macOS/Windows)
docker run -d --network host nginx

# Container listens directly on host port 80
# No -p flag needed (or possible)

# Verify: container's network interfaces = host interfaces
docker exec -it my-container ip addr

Note: Host networking only works on Linux. Docker Desktop on macOS/Windows runs containers inside a Linux VM, so host networking connects to the VM's network, not the macOS/Windows host.