Understanding Docker Networking: Bridge, Host, and Overlay
Container networking is confusing. Bridge networks, port mapping, host networking — here's how it all works.
The Basics
Every container gets its own network namespace — it has its own IP address, routing table, and network interfaces. The question is: how do containers communicate with each other and the outside world?
Network Modes
Bridge (Default)
Containers connect to a virtual bridge network on the host. Each container gets a private IP (172.17.x.x by default).
Host
Container shares the host's network directly. No network isolation.
None
No networking. Container is completely isolated.
User-Defined Bridge Networks
Always create your own bridge networks instead of using the default:
docker network create mynetwork
Benefits over the default bridge:
Port Mapping
-p 8080:80 maps host port 8080 to container port 80.
-p 127.0.0.1:8080:80 binds only to localhost (not accessible from outside).
-p 8080:80/udp for UDP ports.
Container-to-Container Communication
Containers on the same user-defined bridge network can communicate by name:
App container connects to database as: postgres://db:5432/mydb
(where "db" is the database container's name)
DNS Resolution
Docker's embedded DNS server resolves container names to IPs within user-defined networks. This is why you see hostnames like "db" or "redis" in docker-compose files instead of IP addresses.
Common Patterns
Web App + Database
Reverse Proxy
Podman Networking
Podman networking is similar to Docker's but with a key difference: rootless Podman uses slirp4netns or pasta for network namespace setup instead of iptables, since regular users can't modify iptables rules.