Overlay networks and VXLAN
An overlay network makes containers on different hosts look like they share one switch, by tunneling their traffic.
? What do the diagram colours mean
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
Docker’s built-in overlay driver needs a cluster manager to share network state between hosts. In Docker that is Swarm mode.
| 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
--attachable and then trying docker run --network on it. Without the flag, only Swarm services can join.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 reach each other’s containers over the overlay. Which port do you check first?
Show answer
Answer: UDP 4789
UDP 4789 carries VXLAN data. A firewall that blocks it breaks overlay traffic while discovery on 7946 may still work.
What does the physical network see when A on host 1 talks to B on host 2?
Show answer
Answer: A UDP packet between the two host IPs.
VXLAN wraps the frame in UDP between host addresses. The inner packet is untouched.