Docker networking explained in plain terms: it is the system that lets containers talk to each other, to the host machine and to the outside world, using virtual networks that Docker creates and manages. Every container gets its own network namespace, and Docker connects that namespace to a network through a driver. The short answer is that Docker builds a small virtual network for your containers, gives each one an address on it, and uses port publishing and an embedded DNS server so services can find each other by name.
The confusion starts when two containers need to communicate, when a service must be reachable from a browser, or when containers on different hosts must behave as if they shared one network. This guide explains the drivers, name resolution, port publishing and the mistakes that expose services by accident. If containers are new to you, our guide to cloud native computing sets out the mental model this article builds on.
Key takeaways
- Docker networking gives every container its own network namespace, connected to a virtual network through a driver such as bridge, host, overlay or macvlan.
- The default bridge network provides no DNS between containers, so create a user-defined bridge network for any application with more than one container.
- Containers on the same user-defined network resolve each other by name through Docker’s embedded DNS server at 127.0.0.11.
- Port publishing with -p maps a host port to a container port, and the published port is reachable from outside the host by default.
- Overlay networks span several Docker hosts for Swarm, while macvlan puts containers directly on the physical LAN.
How Docker networking works
When Docker starts a container, it creates a network namespace for it. Inside that namespace, the container’s localhost is its own localhost, not the host’s, which is why two containers can both listen on port 8080 without clashing.
Docker then connects the container’s namespace to a network. On a single host the usual connection is a Linux bridge, a virtual switch that forwards packets between the containers attached to it. Each container gets a virtual Ethernet interface, and the other end sits on the bridge, so traffic between containers on the same bridge travels through the virtual switch rather than the physical network.
For traffic to the outside world, Docker uses network address translation, or NAT. Outgoing packets leave through the host’s real interface with the host’s address, and replies are translated back to the right container. Best for: understanding why a container’s IP address is only meaningful on its own host.
The network drivers at a glance
Docker ships with several network drivers, and choosing between them is the first real decision in Docker networking. The bridge driver is the default and the right choice for most single-host applications, while the host driver removes isolation entirely for maximum speed. The none driver gives a container no network at all, overlay networks span multiple hosts for Docker Swarm, and macvlan and ipvlan attach containers directly to the physical network.
| Driver | Scope | Isolation | Typical use |
|---|---|---|---|
| bridge | Single host | Own namespace, NAT to the outside | Most single-host apps and Compose projects |
| host | Single host | None, shares the host stack | Performance-sensitive apps, many ports |
| none | Single host | Loopback only | Batch jobs with no network need |
| overlay | Multi-host | VXLAN tunnel between hosts | Swarm services across several servers |
| macvlan | Single host | Own MAC and IP on the physical LAN | Legacy apps needing a physical device identity |
| ipvlan | Single host | Own IP, shares the host MAC | Networks limiting MAC addresses per port |
The bridge network is backed by an interface called docker0 on the host, and containers started without a network flag join it automatically. Best for: a quick mental map before you create your first custom network.
Default bridge versus a user-defined bridge
The most important distinction in Docker networking is between the default bridge network and a bridge network you create yourself. They look similar, but they behave differently in one way that matters every day: name resolution.
Containers on the default bridge cannot resolve each other by name. If a web container needs to reach a database container there, it must use the database container’s IP address, which changes every time the container is recreated.
The legacy –link flag once worked around this, but it is deprecated and should not be used in new work. Create your own bridge network instead: it gives you the embedded DNS server, isolates its containers from other networks, and lets you connect and disconnect running containers without restarting them.
How containers find each other
Docker’s embedded DNS server listens at 127.0.0.11 inside each container on a user-defined network. When a container looks up another container’s name, Docker answers with its current IP on that network.
This is also why service names work so smoothly in Docker Compose. Each service becomes a DNS name on the project’s network, so a web service can connect to db or cache by name.
One caveat is worth remembering: DNS resolution only works between containers on the same network. A container can join more than one network, so a common pattern is to put a web container on both a frontend and a backend network, while the database sits only on the backend network.
Our guide to cloud networking explained covers the same isolation ideas at the level of virtual networks. Best for: designing which services may talk to which, rather than leaving every container on one flat network.

Publishing ports to the outside world
A container’s ports are private by default. Publishing a port makes a service reachable from the host or the internet, using the -p flag followed by the host port, a colon, and the container port. The command docker run -d -p 8080:80 nginx publishes the container’s port 80 on the host’s port 8080.
The detail that catches people out is that a published port is reachable from outside the host by default. Docker adds firewall rules that bypass the host firewall in many configurations, so a port you thought was only open locally can be reachable from the internet. If a service should only be reachable on the host itself, bind it to the loopback address explicitly, for example -p 127.0.0.1:8080:80.
Port conflicts are another common snag. Two containers cannot publish the same host port, so if two web applications both want port 80, one must use a different host port or sit behind a reverse proxy that routes by hostname.
A reverse proxy is the usual answer in production, because it also adds TLS termination. Best for: any service that must be reachable from a browser, with the loopback binding for anything that should stay private.
Overlay networks and multi-host networking
Bridge networks stop at the edge of one host. When containers run on several servers, as they do in Docker Swarm, an overlay network connects them into a single virtual network that spans all the hosts. Traffic between nodes is encapsulated in VXLAN tunnels, and it can be encrypted with the –opt encrypted flag.
Creating an overlay network needs a Swarm, so the usual sequence is docker swarm init on the first host, joining the others, and then docker network create –driver overlay –attachable backend. The –attachable flag lets standalone containers join the network too, which is handy for debugging.
In practice, overlay networking is now mainly a Swarm feature. Most teams running containers across many hosts have moved to Kubernetes, where the equivalent job is done by a container network interface plugin such as Calico or Cilium. If you are weighing that move, our guide to Kubernetes explained covers what the orchestrator adds on top of plain Docker networking.
Macvlan and ipvlan: containers on the physical LAN
Macvlan and ipvlan take the opposite approach to a bridge: instead of hiding containers behind NAT, they put each container directly on the physical network with its own IP address, so it looks like a separate physical device. This suits legacy applications that expect a real address on the LAN. The trade-off is that the host itself cannot reach its own macvlan containers by default, which surprises almost everyone the first time.
Ipvlan is the sibling driver for networks that limit MAC addresses per switch port, giving each container its own IP while sharing the host’s MAC. Best for: legacy or network-sensitive applications that must appear as ordinary devices on the LAN.
Common Docker networking problems
Most Docker networking failures fall into a small set of patterns. The first is the default bridge trap: two containers cannot find each other by name because they are on the default bridge instead of a user-defined one. The fix is to create a network and attach both containers to it.
The second is a published port that does not respond. The usual causes are that the application inside the container is listening on 127.0.0.1 instead of 0.0.0.0, or that the wrong container port was published. The third is the disappearing service after a recreate: a container’s IP address changes when it is recreated, so anything that cached the old address breaks, while name-based resolution avoids this entirely.
Our guide to common cloud networking problems covers the same failure patterns at cloud scale. Best for: a troubleshooting checklist to work through before rebuilding anything.
Decision framework: choosing a Docker network setup
- Use a user-defined bridge network for any application with two or more containers, and let Compose create one for you when you use Compose.
- Use the default bridge only for a single throwaway container that needs no name resolution.
- Use host networking only when measurements show NAT is a real bottleneck, never as a default, because it removes network isolation.
- Use none for batch jobs and build containers that should not reach the network at all.
- Use an overlay network when Swarm services on different hosts must communicate, and enable encryption for traffic that crosses untrusted networks.
- Use macvlan or ipvlan only when an application must have its own address on the physical LAN.
- Bind published ports to 127.0.0.1 unless the service is genuinely meant to be reachable from outside the host.
- Keep databases and internal services on a backend network that public-facing containers can reach but the internet cannot.
Frequently asked questions
What is Docker networking?
Docker networking is the system that connects containers to each other, to their host and to the outside world. Each container gets its own network namespace, Docker attaches it to a virtual network through a driver, and an embedded DNS server lets containers on the same user-defined network find each other by name.
What is the default Docker network?
The default network is a bridge network called bridge, backed by the docker0 interface on the host, and containers started without a network flag join it automatically. Its main limitation is that containers on it cannot resolve each other by name, so create a user-defined bridge network for real applications.
How do containers communicate with each other?
Containers on the same user-defined bridge network communicate by container name, resolved through Docker’s embedded DNS server at 127.0.0.11. They can also communicate by IP address, but names are stable across container recreations while IP addresses change.
What is the difference between bridge and host networking?
Bridge networking gives the container its own network namespace behind NAT, so it has its own IP address and published ports are mapped explicitly. Host networking removes that isolation and lets the container share the host’s network stack directly, which is faster but means the container’s ports are the host’s ports.
How do I expose a container port to the internet?
Publish it with the -p flag, for example -p 8080:80, which maps host port 8080 to container port 80. A published port is reachable from outside the host by default, so bind it to 127.0.0.1 for local-only services.







