Docker Overlay Networks: Containers Across Multiple Hosts
How overlay networks span hosts: VXLAN encapsulation, Raft state, swarm scope, attachable networks, VIP vs DNSRR endpoints, and the MTU 1450 you can measure yourself.
Published on • November 19, 2026
AI Assistant

A bridge network ends at the edge of its host — that’s the whole point of a bridge. The moment two containers on different machines need to talk as if they shared a switch, you need an overlay network: a virtual layer-2 network built on top of the real one, carried inside encapsulated packets. In Docker, overlays belong to swarm mode, and the details — VXLAN ports, a Raft-replicated control plane, an MTU that quietly shrinks by 50 bytes — explain most of the “works on one node, breaks on two” bugs in production.
The data plane: VXLAN, ports, and MTU
When container A on node 1 sends a frame to container B on node 2, the packet is encapsulated in VXLAN and routed across your physical network as ordinary UDP:
[inner: A → B, overlay addresses]
↓ encapsulate
[outer: node1 IP → node2 IP, UDP 4789, VXLAN header]
↓ your real network
[node2 decapsulates → delivers to B's veth]
To the containers, they’re on one Ethernet segment. To the network, it’s plain UDP between node IPs. Three port groups must be open between nodes for this to work:
| Port | Protocol | Purpose |
|---|---|---|
| 2377 | TCP | Swarm management / Raft |
| 4789 | UDP | VXLAN encapsulated data (the overlay itself) |
| 7946 | TCP + UDP | Network gossip (membership, service discovery) |
Miss 4789 and containers on the same node still work while cross-node traffic dies — the classic symptom. Miss 7946 and nodes can’t even agree on who’s attached.
The encapsulation costs 50 bytes per packet, and Docker compensates by shrinking the MTU inside containers. You can measure it — on a swarm node with an attachable overlay, run a container on it:
docker run -d --name ov-att --network ov-att nginx:alpine
docker exec ov-att ip link show eth0
3: eth0@if9: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1450 qdisc noqueue state UP
mtu 1450 versus 1500 on the gateway bridge (eth1 in the same container) — exactly the 50-byte VXLAN overhead. If your underlay itself runs a reduced MTU (a common cloud setting), the overlay inherits that too, and oversized packets get dropped somewhere you can’t see. When a service times out across nodes but not locally, check MTU before anything else.
The control plane: swarm scope and Raft
Overlay networks are a swarm-mode construct, and Docker enforces that:
docker network create -d overlay ov-test
Error response from daemon: This node is not a swarm manager. Use docker swarm init...
After docker swarm init, the same create succeeds and the network’s identity changes:
docker network inspect ov-test --format '{{.Scope}} {{.Driver}} {{.Attachable}} {{.Options}}'
swarm overlay false map[com.docker.network.driver.overlay.vxlanid_list:4097]
Three things to note. Scope is swarm, not local — the definition lives with the swarm, not the node, which is why docker network ls shows overlays alongside ingress with the scope column reading swarm. A VXLAN ID is allocated (vxlanid_list), a per-network VNI that keeps multiple overlays from colliding. And the network’s membership state — which nodes joined, which services attach — is replicated by Raft consensus among the manager nodes, so losing quorum loses the control plane even while existing data traffic keeps flowing.
Attachable: the detail that trips up ad-hoc containers
By default an overlay is attachable=false — only services may join it. A plain docker run on that network gets refused before it starts:
docker run --rm --network ov-test alpine echo hi
docker: Error response from daemon: ... PermissionDenied desc = network ov-test not manually attachable
Create it with --attachable (or tick Attachable in a stack file) and normal containers can join — handy for debugging a service network from a throwaway container. The asymmetry between “service-attached” and “manually attachable” is invisible until you hit it, so it belongs in your network-creation habit:
docker network create -d overlay --attachable ov-debug
Service addressing: VIP, DNSRR, and tasks.
Swarm services on an overlay get their own naming layer, and the default endpoint mode is VIP (virtual IP). With a service named web-svc running two tasks, DNS answers differently depending on what you ask for:
nslookup web-svc # → 10.0.1.4 (one stable virtual IP)
nslookup tasks.web-svc # → 10.0.1.6, 10.0.1.5 (each task, round-robin)
The VIP load-balances across tasks inside the overlay — clients get one address that never changes while replicas come and go, and traffic is spread at the network layer. The tasks.<service> name is the escape hatch: it returns every task’s individual address, which is what you want for databases, sticky connections, or any client that must pick a peer itself. Setting endpoint_mode: dnsrr on the service flips the primary name to per-task behavior instead.
Combined with the VXLAN data plane, this is the complete model: Raft keeps the control plane consistent, DNS/VIP keeps the addresses stable, VXLAN carries the frames, and gossip keeps membership honest.
When overlay is the right tool
Overlay networking exists for multi-host service-to-service traffic inside a swarm — microservices that outgrow one machine, rolling updates where new task IPs must be discoverable instantly, and any workload that should keep working when a node dies. It is not a general VPN: attaching your laptop to an overlay requires --attachable, traffic between nodes must be allowed through your firewall on the ports above, and encryption (a per-network --opt encrypted flag) is a separate decision with its own performance cost. If you need containers on one host to talk, stay on a bridge — overlays buy you nothing there but overhead.
The bottom line
An overlay network is a VXLAN-backed virtual switch whose membership and addressing are managed by swarm mode over Raft: UDP 4789 carries the frames, the MTU drops to 1450 by design, swarm-scope definitions replicate across managers, and non-attachable networks refuse stray docker run containers by default. Learn those four mechanics — encapsulation, ports, scope, attachability — and multi-host container networking stops being mysterious and starts being plumbing you can debug with ip link and nslookup.