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.
Related Products
on GumroadDeveloper Productivity Bundle
Stop rebuilding the same setup every project. 51 VSCode snippets, 40 Git aliases, 5 Docker Compose stacks, 5 GitHub Actions workflows, 5 README templates, and a dotfiles kit. Set up a professional dev environment in under an hour.
Buy on Gumroad →AI Prompt Engineering Toolkit
58 structured prompt templates for Claude, ChatGPT, and Gemini — organized by use case. Code Review, Debugging, Documentation, Architecture, and 10 model-specific tips. Stop writing prompts from scratch.
Buy on Gumroad →Developer Cheat Sheet Bundle
10 print-ready cheat sheets for the tools developers use every day: Git, Docker, Linux CLI, SQL, Regex, HTTP Status codes, VS Code shortcuts, Bash scripting, jq/JSON, and Markdown.
Buy on Gumroad →You Might Also Need
JSON Formatter & Validator
Format, beautify, and validate JSON online. Paste your JSON to instantly pretty-print it with 2-space, 4-space, or tab indentation. Minify JSON too. Free, runs in your browser.
Open free tool →
Regex Tester
Free regex tester. Test regular expressions against multiple strings with expected match/no-match assertions — see instant pass/fail results. Built-in presets for email, URL, IPv4, and phone. Pro: unl
Open free tool →
Base64 Encoder & Decoder
Free Base64 Encoder & Decoder. Convert text, images, and any file to Base64 and back. Supports URL-safe Base64, image data URIs, and file download from Base64. Runs 100% in your browser — no data sent
Open free tool →
More Free Tools
Related Articles
curl 深度使用手冊:API 測試從入門到進階
curl 是每位開發者必備的 CLI 工具。本文涵蓋 GET/POST/PUT/DELETE 請求、認證、header 設定、檔案上傳、除錯技巧,以及 REST API 測試的完整實戰範例。
Best AI Code Review Tools 2026: CodeRabbit, Sourcery, DeepCode & Bito Compared
Compare top AI code review tools for 2026: CodeRabbit, Sourcery, DeepCode, and Bito. Features, pricing, GitHub/GitLab integration, and choosing the right tool for your team.
AI Code Review Tools 2026: GitHub Copilot, CodeRabbit, Qodo Merge Ranked
Compare AI code review tools for 2026: GitHub Copilot code review, CodeRabbit, Qodo Merge, Sourcery, and PR-Agent. Pricing, accuracy, and GitHub integration.
AI Coding Tools Comparison 2026: GitHub Copilot vs Cursor vs Windsurf vs Cline
Comprehensive comparison of the best AI coding tools in 2026: GitHub Copilot, Cursor, Windsurf, and Cline. Pricing, features, model support, and real-world benchmarks.
AI Pair Programming in 2026: GitHub Copilot vs Cursor vs Claude Code
Master AI pair programming in 2026. Compare GitHub Copilot, Cursor, and Claude Code for autocomplete, chat, and agentic workflows. Includes setup guides and productivity tips.
Enjoying this tool? Get more like it.
Weekly developer tool guides, productivity playbooks & AI tricks. Free. No spam.
Unlock AI-Powered Dev Tools
- ⚡ AI Code Review, Doc Generator & SQL Builder
- ⚡ All premium templates & early access
- ⚡ Member discounts on Gumroad products
$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.
MIT licensed · Instant download · No subscription
See what's included → Browse all deals →Docker Network Drivers Comparison
| Driver | Scope | Isolation | DNS | Use case |
|---|---|---|---|---|
| bridge | Single host | Virtual L2 subnet | User-defined only | Default for single-host apps |
| host | Single host | None (shares host network) | Host DNS | Max performance, monitoring |
| overlay | Multi-host | VXLAN tunnel | Yes (Swarm services) | Docker Swarm, multi-host |
| macvlan | Single host | Physical MAC address | DHCP / static | Legacy apps, raw network access |
| none | N/A | Complete isolation | None | Batch 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 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.