When two containers need to talk and they’re on different hosts, the single-host bridge driver doesn’t help. Docker’s overlay driver creates a virtual L2 network that spans hosts using VXLAN encapsulation. It’s the foundation under Swarm services, and even without Swarm, it’s the answer when you want container-to-container DNS across machines. This article covers when overlay is the right tool, the Swarm setup it requires, and the operational notes that come up in real deployments.
How to verify
Inspect Swarm state and overlay networks on a node:
docker info | grep -E "Swarm|Is Manager|Nodes"
docker node ls
docker network ls --filter driver=overlay
docker network inspect <overlay-net> | jq '.[].Containers'
# VXLAN interface on the host
ip -d link show | grep -A2 vxlan
sudo nft list table inet swarm-ingress 2>/dev/null
If docker info reports Swarm: inactive, overlay networks won’t work — they require Swarm’s KV store to coordinate state. docker network ls should show ingress (Swarm’s built-in overlay) plus any user-defined overlay networks you’ve created.
What’s happening
An overlay network is implemented as a VXLAN tunnel between each pair of hosts that has a container on the network. Each container gets a virtual interface in the overlay’s subnet (e.g. 10.0.1.0/24); when the container sends a packet to a peer on another host, the packet is wrapped in a VXLAN header (UDP port 4789), sent to the peer host’s IP, unwrapped, and delivered to the destination container.
Swarm provides the control plane: a Raft-replicated KV store that tells every node which containers are on which host and what their overlay IPs are. Without Swarm, Docker has no way to coordinate this — so even though --driver overlay works without Swarm, you’d need to bring your own KV store (Consul, etcd), which nobody does in 2026.
Encryption is optional: --opt encrypted on the overlay enables IPSec on the VXLAN traffic. Slower (5-15% throughput hit, more CPU), but the data path between hosts is encrypted in transit. Useful when overlay traffic crosses an untrusted network (e.g. between cloud regions, between on-prem and cloud).
The procedure
- Initialize Swarm on the first node. This becomes the initial manager:
# On node-1
docker swarm init --advertise-addr <node-1-IP>
# Output includes a join token; save it
--advertise-addr is the IP other nodes will use to reach this one. Use the private/internal IP, not the public one, when nodes are in the same network.
- Join other nodes to the swarm:
# On node-2, node-3 — worker join token from step 1
docker swarm join --token SWMTKN-1-... <node-1-IP>:2377
# To add another manager (always run 3 or 5 managers for quorum)
docker swarm join-token manager # on existing manager
# Then run the printed command on the new manager candidate
Ports that must be open between Swarm nodes:
2377/tcp— cluster management API7946/tcpand7946/udp— node discovery (gossip)4789/udp— VXLAN data path50/ip— IPSec ESP (only if--opt encrypted)
- Create an encrypted overlay network for application traffic:
docker network create \
--driver overlay \
--opt encrypted \
--subnet 10.20.0.0/24 \
--attachable \
app-net
--attachable lets you run docker run --network app-net on any node (not just Swarm services). Without it, only docker service workloads can attach.
- Deploy a Swarm service that spans nodes:
docker service create \
--name web \
--replicas 3 \
--network app-net \
--publish published=8080,target=8080 \
--update-parallelism 1 \
--update-delay 30s \
--update-failure-action rollback \
--restart-condition any \
ghcr.io/example/web:1.42.0
Swarm distributes the 3 replicas across nodes. The publish flag uses Swarm’s ingress network — any node receiving traffic on port 8080 routes it to whichever replica is healthy (round-robin via the ingress routing mesh).
- Inspect what Swarm did:
docker service ls
docker service ps web
docker service inspect web --pretty
docker service logs web --tail 50
# Per-node view
docker ps # only containers on the current node
docker node ps <node-name> # containers Swarm placed on a specific node
- Update a service. Swarm orchestrates a rolling update based on the update policy you set at create time:
docker service update --image ghcr.io/example/web:1.43.0 web
# Watch the rollout
docker service ps web --filter desired-state=running
--update-parallelism 1 --update-delay 30s means one task at a time, 30 seconds between batches. If a batch fails, --update-failure-action rollback reverts to the previous image.
- Use Docker Stack to deploy from a Compose file:
# Same compose.yaml works, with a few Swarm-only keys
docker stack deploy -c compose.yaml myapp
docker stack services myapp
docker stack ps myapp
docker stack rm myapp
The deploy: block in Compose is consumed by Swarm:
services:
web:
image: ghcr.io/example/web:1.42.0
deploy:
replicas: 3
restart_policy:
condition: any
delay: 5s
update_config:
parallelism: 1
delay: 30s
failure_action: rollback
resources:
limits:
memory: 512m
cpus: '1.0'
placement:
constraints:
- node.role == worker
networks:
- app-net
networks:
app-net:
driver: overlay
attachable: true
encrypted: true
- Lock the Swarm. Without autolock, the Raft state is encrypted with a key stored on disk in plaintext — anyone with root on a manager has full cluster access. With autolock, the key is removed and must be supplied at daemon start:
docker swarm update --autolock=true
# Save the unlock key it prints
# After daemon restart:
docker swarm unlock
# Paste the unlock key
Common pitfalls
- Forgetting to open the Swarm ports between nodes — services start but nothing can talk to anything. Verify with
sudo nft list ruleset(oriptables-save) and anetcatprobe between hosts. - Running overlay without
--opt encryptedon networks that cross the public internet. The default is unencrypted VXLAN; anyone with packet capture between the hosts sees the container traffic. - Skipping autolock and losing the cluster the first time a manager is compromised — the Raft KV store contains every secret, every service config.
- Running 2 managers (no quorum) or 4 (even number). Always odd — 3 or 5.
- Mixing
docker serviceanddocker runon the same overlay without--attachable. Plaindocker runwill refuse to connect, and you’ll have a confusing dual-deploy mess. - Letting the ingress network become the bottleneck. The routing mesh is convenient but routes every request through whichever node received the packet; for high-throughput services, run a real load balancer in front of Swarm and use the long-form publish
mode=hostto bypass the mesh.
For most clients, we’ve moved past Swarm — Kubernetes (or a managed PaaS) is where multi-host orchestration lives in 2026. Swarm remains a fit for small fleets (3-10 nodes) where the operational simplicity outweighs the feature gap. When we run Swarm clusters, autolock, encrypted overlays, and the Compose-stack workflow are all part of the managed operations baseline.