Networking: overlay networks and VXLAN
An overlay network makes containers on different hosts look like they share one switch, by tunneling their traffic.
key idea / Docker itselfcontainer / good pathhost / watch outproblem / blockedneutral
One network, many hosts
VXLAN: a packet inside a packet
Swarm and the ports it needs
The built-in overlay driver expects Swarm to share network state.
| Port | Protocol | Carries |
|---|---|---|
| 2377 | TCP | swarm management (managers) |
| 7946 | TCP and UDP | node-to-node discovery and gossip |
| 4789 | UDP | VXLAN overlay traffic |
Try it yourself
One machine is enough to see the objects. Packets only cross hosts after a second node joins.
-
Step 1 · Start Swarm
$ docker swarm init Swarm initialized: current node (abc123) is now a manager. docker swarm join --token SWMTKN-1-… 192.168.1.20:2377 -
Step 2 · Create the overlay
--attachablelets a normaldocker runjoin it. Without that flag, only Swarm services can attach.$ docker network create -d overlay --attachable app $ docker network inspect app --format '{{.Driver}} {{.Scope}}' overlay swarm -
Step 3 · Run a service on it
$ docker service create --name api --network app alpine:3.20 sleep 300 $ docker service ls ID NAME MODE REPLICAS IMAGE xy91aa api replicated 1/1 alpine:3.20 $ docker service ps api ID NAME NODE DESIRED STATE CURRENT STATE cd33ef api.1 this-node Running Running -
Step 4 · The ports between nodes
Open these between managers and workers before you expect cross-host traffic. UDP 4789 carries the VXLAN packets.
TCP 2377 swarm management TCP/UDP 7946 node discovery UDP 4789 overlay data (VXLAN) $ docker service rm api $ docker network rm app $ docker swarm leave --force
Recap
- An overlay gives containers on different hosts addresses in one subnet.
- VXLAN wraps the container frame inside UDP (port 4789) between the hosts.
- The built-in overlay needs Swarm: TCP 2377, TCP+UDP 7946, UDP 4789 open between nodes.
--attachablelets plaindocker runcontainers join the overlay.
Quick check
Two Swarm hosts cannot ping each other's containers across the overlay. Which port do you check first?
Show answer
UDP 4789, the VXLAN data port. A firewall that blocks it breaks overlay traffic while node discovery on 7946 may still work.