Service discovery in Docker Swarm enables containers and services to locate and communicate with each other by name, rather than by changing IP addresses. This improves reliability and simplifies your microservices architecture.Documentation Index
Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
Use this file to discover all available pages before exploring further.
Container-to-Container Communication
By default, Docker Engine allows containers on the same node to resolve each other by container name via its built-in DNS server at127.0.0.11. Relying on container names prevents issues when IPs change after restarts.
Service Discovery in Docker Swarm
In Swarm mode, every service is assigned a DNS entry matching its service name. Load balancing is handled automatically across all replicas.web service can connect to api-server simply by its name:
api-server are distributed across its replicas.
Using a Custom Overlay Network
DNS-based service discovery only works on user-defined networks. The defaultbridge and ingress networks do not support inter-service name resolution. Create an overlay network to enable DNS resolution across multiple swarm nodes:
api-server resolves to one of its replicas whenever any service on app-network queries its name.
Always attach your services to a user-defined overlay network for reliable DNS-based service discovery in Swarm.
Network Comparison
| Network Type | DNS Resolution Between Services | Scope |
|---|---|---|
Default bridge | No | Single host only |
| Ingress | Routing mesh only | Cluster-wide load balancing |
| User-defined overlay | Yes | Multi-host overlay |