Overlay Networking Fundamentals for Docker Swarm
Swarm overlay networks explained end to end: swarm init, network create -d overlay, cross-host task traffic over VXLAN, VIP vs dnsrr endpoints, and attachable networks.
Published on • November 19, 2026
AI Assistant

Bridge networks stop at the host boundary. The moment you need a container on one machine to reach a container on another as if they shared a switch, you need an overlay — Docker’s built-in driver for exactly that. It has one prerequisite that catches people off guard: every host must already be in a swarm, even if all you ever plan to run is plain docker run.
The prerequisite: swarm membership and three ports
When you initialize or join a swarm, two networks appear on every host automatically: ingress (an overlay that feeds the routing mesh) and docker_gwbridge (a per-host bridge that gives containers a path off the box). Everything overlay-shaped rides on three ports being open between participating hosts:
| Port | What it carries |
|---|---|
2377/tcp | Swarm control plane: joining, leaving, scheduling. Configurable with docker swarm join --listen-addr. |
4789/udp | The overlay data path itself — VXLAN. Configurable with docker swarm init --data-path-port. |
7946/tcp, 7946/udp | Node discovery and node-to-node communication. Not configurable. |
$ docker swarm init --advertise-addr 10.0.0.11
Swarm initialized: current node (vz1mm9am11qcmo979tlrlox42) is now a manager.
# on the second host:
$ docker swarm join --token SWMTKN-1-5g90q48weqrtqryq4kj6ow0e8xm9wmv9o6vgqc5j320ymybd5c 10.0.0.11:2377
This node joined a swarm as a worker.
Docker refuses to create an overlay on a standalone daemon — the driver’s scope is swarm, not local. That’s why even the “standalone containers on two hosts” use case still starts with swarm init.
Create and inspect the network
Creating an overlay looks identical to creating a bridge, and it must be run from a manager:
$ docker network create -d overlay nginx-net
495c570066bec8357deec9cb
$ docker network ls
NETWORK ID NAME DRIVER SCOPE
495c570066be bridge bridge local
66e77d0d0e9a docker_gwbridge bridge local
trtnl4tqnc3n ingress overlay swarm
495c570066be nginx-net overlay swarm
The SCOPE column is the tell: swarm networks only exist for hosts participating in the swarm. Inspect shows the rest:
$ docker network inspect nginx-net
"Scope": "swarm",
"Driver": "overlay",
"IPAM": {
"Config": [ { "Subnet": "10.0.0.0/24", "Gateway": "10.0.0.1" } ]
},
"Options": {
"com.docker.network.driver.overlay.vxlanid_list": "4097"
}
If you don’t specify --subnet, the subnet and gateway are assigned dynamically the first time a service connects — the VXLAN ID list is the VNI allocation the driver manages for you. The network propagates to worker nodes automatically when a task needs it, but it is not automatically removed when you’re done; clean up with docker network rm after removing the services.
Tasks on two hosts, one network
$ docker service create --name my-nginx --replicas 2 \
--network nginx-net \
--publish published=8080,target=80 \
nginx:1.27
$ docker service ps my-nginx
ID NAME NODE DESIRED STATE CURRENT STATE
8k2n1... my-nginx.1 ip-10-0-0-11 Running Running 41 seconds ago
4vp9c... my-nginx.2 ip-10-0-0-12 Running Running 41 seconds ago
Each task gets an address on nginx-net, wherever it lands. When task 1 talks to task 2, the host encapsulates the Ethernet frame in VXLAN and ships it over UDP 4789 to the peer — from inside the containers, none of that is visible. They see one flat L2 segment, and the embedded DNS resolves peers by name:
$ docker exec $(docker ps -q -f name=my-nginx.1) ping -c 2 my-nginx
PING my-nginx (10.0.0.4): 56 data bytes
64 bytes from 10.0.0.4: seq=0 ttl=64 time=0.61 ms
64 bytes from 10.0.0.4: seq=1 ttl=64 time=0.58 ms
my-nginx resolved to 10.0.0.4 — a virtual IP. To get the individual task addresses instead, look up tasks.<service-name>:
$ docker exec $(docker ps -q -f name=my-nginx.1) getent hosts tasks.my-nginx
10.0.0.5 my-nginx.2
10.0.0.3 my-nginx.1
VIP vs dnsrr: pick your endpoint mode
Docker offers two endpoint modes per service, and the default matters more than it looks:
vip (default) | dnsrr | |
|---|---|---|
| DNS answer for the service name | one virtual IP | a list of task IPs |
| Who load-balances | IPVS inside the swarm, per request | your client, or an external LB |
Works with --publish mode=ingress | yes | no |
| Scales past 256 addresses | no — see the /24 rule | yes, with an external load balancer |
$ docker service create --name api --replicas 3 \
--endpoint-mode dnsrr \
--network nginx-net \
my/api:1.4
With dnsrr, a lookup of api returns all three task IPs directly and the client connects to one of them — the shape you want when HAProxy or a similar load balancer in front of the service should make the picking decision. Note the hard constraint: you can’t combine --endpoint-mode dnsrr with --publish mode=ingress, because the routing mesh is built around the VIP. Drop the published port and put your own LB in front.
Related: Docker recommends keeping overlay networks at /24 (256 addresses) in VIP mode, because of a swarm limitation. If you need more addresses, don’t grow the block — split into several networks, or move to dnsrr with an external load balancer.
Attachable: docker run on the overlay
By default, only swarm services may attach to an overlay. That restriction is deliberate: it stops someone with shell access on a non-manager node from starting a container attached to a service’s network stack. For ops containers and debugging, opt in with --attachable:
$ docker network create -d overlay --attachable ops-net
$ docker run -it --rm --network ops-net alpine ping -c 2 my-nginx
PING my-nginx (10.0.0.4): 56 data bytes
64 bytes from 10.0.0.4: seq=0 ttl=64 time=0.63 ms
The standalone container can reach service tasks by name across hosts — provided the overlay is attachable and container names are unique, since DNS discovery keys off them.
How the routing mesh fits alongside your overlay
Two overlays, two directions of traffic. Your nginx-net carries east-west traffic between tasks. The ingress network carries north-south: every node listens on the published port 8080 whether or not a task runs there, and IPVS hands the request to a task over ingress. Each task is additionally wired to its local docker_gwbridge — that’s how it gets default-route egress and how published traffic flows back out.
$ docker network ls
NETWORK ID NAME DRIVER SCOPE
495c570066be docker_gwbridge bridge local
trtnl4tqnc3n ingress overlay swarm
495c570066be nginx-net overlay swarm
Keep them separate: one overlay network per application or related group is Docker’s own recommendation, rather than dumping everything onto ingress.
Limits worth remembering
- 1000 containers per host on a single overlay is the documented instability threshold (moby/moby#44973).
/24per overlay in VIP mode, as above.- The data plane is unencrypted by default. Control and management traffic is always encrypted; application traffic crossing between hosts is not, unless you create the network with
--opt encrypted— the subject of our companion post on encrypting overlay traffic.
The bottom line
An overlay network is a swarm-scoped, VXLAN-backed L2 segment that spans every host in the cluster: create it once with docker network create -d overlay, attach services with --network, and tasks can reach each other by name wherever the scheduler puts them. Choose vip for built-in load balancing or dnsrr when your own load balancer should pick targets, add --attachable if plain containers need on-board, and remember the three open ports, the /24 guidance, and the 1000-container ceiling. The routing mesh and docker_gwbridge handle everything north-south; your overlay is purely for the traffic between your own tasks.