Docker Swarm overlay networks, ingress mesh, and VIP vs DNSRR
Compare VIP and DNSRR discovery on Docker Swarm overlay networks, and verify ingress routing mesh SNAT versus mode=host client IP preservation on 3 nodes.
A user-defined Docker Swarm overlay network connects tasks across hosts on one virtual subnet with built-in DNS and IPVS load balancing. On a 3-node cluster, I compared
vipagainstdnsrrservice discovery and verified howmode=ingressmasks the client IP through SNAT whilemode=hostpreserves it.
All commands and outputs below ran on an isolated 3-node
docker:29-dindcluster (swarm-mgr1,swarm-wrk1,swarm-wrk2, Docker Engine29.10.1,linux/arm64) with a separate external client container (172.22.0.5). Services rantraefik/whoami:v1.10.3, and DNS lookups ran fromalpine:3.21.
How overlay networks span multiple hosts with VXLAN
On a single host, Docker bridge networks and DNS service discovery or isolated internal and shared external Compose networks cover container-to-container traffic. Once you add a second host, each engine has its own local bridge subnet and containers can no longer reach peers on another node by service name.
Docker Swarm solves this with VXLAN-based overlay networks. Swarm daemons exchange network membership and task-to-IP mappings over the gossip control plane (TCP/UDP 7946), then encapsulate cross-node container packets inside VXLAN frames (UDP 4789) over the underlying host network. Inside the container, tasks on different hosts share one virtual subnet (10.0.1.0/24 in this test).
Start by creating an attachable overlay network and three test services. Adding --attachable lets standalone containers (docker run --network app-overlay) join the network for debugging alongside Swarm tasks. Every service uses --constraint 'node.role==worker' so swarm-mgr1 runs zero tasks, which makes the difference between ingress forwarding and host-mode binding easy to observe.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# 1) Create a user-defined attachable overlay network
docker network create --driver overlay --attachable app-overlay
# 2) VIP + Ingress Routing Mesh service (workers only -> 0 tasks on manager)
docker service create --name who-vip \
--network app-overlay --replicas 2 --endpoint-mode vip \
--constraint 'node.role==worker' \
--publish mode=ingress,published=8080,target=80 \
traefik/whoami:v1.10.3
# 3) DNSRR service (no VIP; cannot be combined with mode=ingress)
docker service create --name who-dnsrr \
--network app-overlay --replicas 2 --endpoint-mode dnsrr \
--constraint 'node.role==worker' \
traefik/whoami:v1.10.3
# 4) mode=host published service (workers only)
docker service create --name who-host \
--network app-overlay --replicas 2 \
--constraint 'node.role==worker' \
--publish mode=host,published=8082,target=80 \
traefik/whoami:v1.10.3
Comparing VIP and DNSRR service discovery
Swarm supports two --endpoint-mode values: vip (the default) and dnsrr (DNS round-robin).
vipmode: Swarm assigns a single virtual IP (VIP) per service on each attached network. When a client resolves the service name through the embedded DNS server (127.0.0.11), it gets that VIP, and the Linux kernel’s IPVS distributes connections across backend task IPs.dnsrrmode: Swarm skips VIP allocation. Each DNS lookup for the service name returns the list of individual running task IPs directly in round-robin order.
Inspecting Endpoint.VirtualIPs and running nslookup from an alpine:3.21 container on app-overlay shows the difference directly:
1
2
3
4
5
6
7
# Inspect VirtualIPs
docker service inspect who-vip --format '{{json .Endpoint.VirtualIPs}}'
docker service inspect who-dnsrr --format '{{json .Endpoint.VirtualIPs}}'
# Resolve service names inside app-overlay
docker run --rm --network app-overlay alpine:3.21 sh -c \
'nslookup who-vip && nslookup tasks.who-vip && nslookup who-dnsrr'
1
2
3
4
5
6
7
8
# VirtualIPs comparison
who-vip VirtualIPs: [{"NetworkID":"ghdi5di...","Addr":"10.0.0.5/24"},{"NetworkID":"vfh5ur6...","Addr":"10.0.1.2/24"}]
who-dnsrr VirtualIPs: null
# DNS lookup results inside app-overlay
Name: who-vip Address: 10.0.1.2 # single VIP
Name: tasks.who-vip Address: 10.0.1.3, 10.0.1.4 # 2 individual task IPs
Name: who-dnsrr Address: 10.0.1.8, 10.0.1.7 # task IPs returned directly without a VIP
who-vip received one VIP on the ingress network (10.0.0.5/24) and one on app-overlay (10.0.1.2/24). Resolving who-vip returned only 10.0.1.2, yet six sequential HTTP requests to http://who-vip split evenly 3 and 3 between 10.0.1.3 and 10.0.1.4 via IPVS. When you still need individual task addresses under vip mode, query tasks.<service-name> (tasks.who-vip).
who-dnsrr had VirtualIPs: null, and nslookup who-dnsrr returned 10.0.1.8 and 10.0.1.7 directly. Because dnsrr has no VIP, you can’t publish a port with mode=ingress on a dnsrr service. Swarm rejects that combination immediately:
1
2
# Combining --endpoint-mode dnsrr with --publish mode=ingress (exit code 1)
Error response from daemon: rpc error: code = InvalidArgument desc = EndpointSpec: port published with ingress mode can't be used with dnsrr mode
If an externally reachable service needs dnsrr, either publish its port with mode=host or place a reverse proxy (such as HAProxy, NGINX, or Traefik) in front of it and let the proxy resolve the dnsrr backend inside the overlay network.
Ingress routing mesh SNAT versus mode=host client IP
As shown in replicating services and moving tasks with Docker Swarm, mode=ingress listens on the published port across every node in the swarm. Even when a node runs zero tasks for that service, its ingress network sandbox receives the packet and forwards it through IPVS and VXLAN to a worker running the task.
By contrast, mode=host bypasses the routing mesh and binds directly to the host port only on nodes that run a task. The two paths behave differently for an external client (172.22.0.5):
flowchart TD
C["External client (172.22.0.5)"]
M["swarm-mgr1:8080 (0 tasks)"]
IG["ingress sandbox (SNAT 10.0.0.2)"]
W1["swarm-wrk1 task (10.0.1.3)"]
W2["swarm-wrk2 task (10.0.1.4)"]
WH["swarm-wrk1:8082 (mode=host)"]
C -->|"Ingress :8080"| M
M --> IG
IG -->|"IPVS/VXLAN"| W1
IG -->|"IPVS/VXLAN"| W2
C -->|"Host :8082 direct"| WH
Sending requests from 172.22.0.5 to swarm-mgr1 (172.22.0.2) and the workers (172.22.0.3, 172.22.0.4) on :8080 (mode=ingress) and :8082 (mode=host) produced these responses:
1
2
3
4
5
6
7
8
9
10
11
# [mode=ingress :8080] swarm-mgr1 (0 tasks) succeeds 4/4, balanced across workers
mgr1:8080 req#1: Hostname: 0e528cb68127 ... IP: 10.0.1.3 RemoteAddr: 10.0.0.2:42850
mgr1:8080 req#2: Hostname: 866d65d34bd8 ... IP: 10.0.1.4 RemoteAddr: 10.0.0.2:42860
wrk1:8080 req#1: Hostname: 0e528cb68127 ... IP: 10.0.1.3 RemoteAddr: 10.0.0.3:36580
# [mode=host :8082] swarm-mgr1 (0 tasks) rejects connection immediately (exit code 1)
wget: can't connect to remote host (172.22.0.2): Connection refused
# [mode=host :8082] direct worker request preserves real client IP
wrk1:8082 req#1: Hostname: c0a2a6a91ad4 ... IP: 10.0.1.11 RemoteAddr: 172.22.0.5:45424
wrk2:8082 req#1: Hostname: 996c09043f3c ... IP: 10.0.1.10 RemoteAddr: 172.22.0.5:33628
Two practical differences stand out:
mode=ingress(:8080): All four requests toswarm-mgr1succeeded and alternated between the two worker tasks (0e528cb68127and866d65d34bd8), even though the manager ran no tasks. However, the application sawRemoteAddr: 10.0.0.2(the manager’singresssandbox IP) instead of172.22.0.5. Hittingswarm-wrk1:8080showedRemoteAddr: 10.0.0.3for the same reason: the ingress mesh applies SNAT.mode=host(:8082):swarm-mgr1refused the connection immediately because nothing bound port8082on that host. Callingswarm-wrk1:8082orswarm-wrk2:8082hit the local task directly and preservedRemoteAddr: 172.22.0.5.
Choosing between VIP vs DNSRR and ingress vs mode=host
Treat internal discovery (vip vs dnsrr) and external port publishing (mode=ingress vs mode=host) as two separate decisions.
| Criteria | --endpoint-mode vip (default) | --endpoint-mode dnsrr |
|---|---|---|
| VIP allocation | One VIP per attached network | None (VirtualIPs: null) |
| DNS response | Single VIP (tasks.<name> for task IPs) | Round-robin list of individual task IPs |
| Load balancer | Linux kernel IPVS on each node | Client or external reverse proxy |
mode=ingress support | Supported | Rejected (InvalidArgument) |
| Best fit | Standard internal HTTP/TCP services | Custom L7 proxies (HAProxy, NGINX) managing their own pools |
| Criteria | mode=ingress (default) | mode=host |
|---|---|---|
| Nodes without tasks | Forwards traffic via routing mesh | Fails with Connection refused |
| Real client IP | Masked by ingress SNAT (10.0.0.x) | Preserved directly |
| Multiple replicas per node | Supported on the same published port | Port conflict (max 1 task per node) |
| Best fit | Simple exposure without an external LB | Edge reverse proxies (global mode) behind an external LB |
Knowing when not to use each option prevents surprises in production:
- Skip
mode=ingresswhen IP-based rate limiting, allowlists, or audit logs need the real client IP and no upstream proxy injectsX-Forwarded-Foror PROXY protocol. Under ingress SNAT, every external caller looks like10.0.0.x, so a single rate-limit rule can lock out all users at once. - Skip
mode=hostwhen you have no external load balancer in front of the nodes or when areplicatedservice must run more than one replica per node. Scheduling a second task onto the same host fails with a port conflict. A common pattern is to publish only aglobaledge reverse proxy (Traefik or NGINX) withmode=host, then route to backend services over the internal overlay network. - Skip
dnsrrif clients aggressively cache DNS answers—such as default JVM DNS caching—because requests can keep targeting an old task IP after a reschedule. Stick withvipunless your proxy actively re-resolves backend records.
Production pitfalls and pre-flight checklist
Watch node firewall ports and encryption overhead: Cross-node overlay traffic requires TCP 2377 (cluster management), TCP/UDP 7946 (gossip control plane), and UDP 4789 (VXLAN data plane) open between cluster nodes. If UDP 4789 is blocked,
docker service lsstill reports2/2, but requests crossing nodes hang and time out. Enabling--opt encryptedadds IPsec overhead and reduces effective MTU, so only enable it when traffic crosses untrusted networks.
Before rolling out overlay networks and published ports, verify these four items:
- Confirm inter-node ports: Verify TCP/UDP 7946 and UDP 4789 are open between all manager and worker nodes in your security groups or host firewalls.
- Restrict ingress exposure: Ports published with
mode=ingresslisten on all host interfaces and bypass Ubuntu UFW rules via iptables. On public-facing nodes, filter traffic in your cloud firewall or theDOCKER-USERchain. - Plan client IP propagation: If your app needs real client IPs, expose a
globaledge proxy withmode=hostand forwardX-Forwarded-Forover the overlay network to internal services. - Account for L4 VIP stickiness: IPVS balances per TCP connection, not per HTTP request. Long-lived HTTP keep-alive or gRPC streams can pin traffic to older tasks after scaling out, so pair those workloads with connection max-age limits or an L7 proxy using
dnsrr.