HashiCorp Consul Cluster
Service mesh and service discovery platform for distributed systems.
Overview
HashiCorp Consul is a distributed service mesh and service discovery platform designed to connect and secure services across any runtime platform and public or private cloud. Originally developed by HashiCorp in 2014, Consul provides a full-featured control plane with service discovery, configuration, and segmentation functionality, enabling organizations to build secure, resilient distributed systems with automatic network configurations and service-to-service communication.
This three-server Consul cluster configuration establishes a highly available service registry with automated leader election and consensus through the Raft protocol. The consul-server nodes form a quorum-based cluster that maintains service catalogs, health checks, and key-value data, while the consul-client acts as a lightweight agent for service registration and discovery. Together, they create a distributed system that can handle node failures while maintaining service visibility and enabling secure inter-service communication through built-in service mesh capabilities.
This stack is ideal for platform engineering teams managing microservices architectures, DevOps engineers implementing service discovery in multi-cloud environments, and organizations requiring centralized configuration management with high availability. The combination of multiple server nodes with client agents provides the redundancy needed for production workloads while offering the flexibility to scale service registration across distributed applications.
Key Features
- Raft consensus algorithm for distributed leader election and data replication
- Built-in service discovery with DNS and HTTP interfaces on ports 8600 and 8500
- Integrated health checking with configurable check intervals and failure thresholds
- Key-value store for dynamic configuration and service metadata
- Service mesh capabilities with Connect for encrypted service-to-service communication
- Multi-datacenter federation support for cross-region service discovery
- Access Control Lists (ACL) system for fine-grained service and data permissions
- Web UI dashboard for cluster visualization and service monitoring
Common Use Cases
- 1Microservices service discovery in Kubernetes or Docker Swarm environments
- 2Multi-cloud service registry for applications spanning AWS, Azure, and GCP
- 3Configuration management for distributed applications requiring dynamic updates
- 4Service mesh implementation for zero-trust networking between microservices
- 5Load balancer backend discovery for HAProxy, NGINX, or cloud load balancers
- 6Cross-datacenter service communication for disaster recovery scenarios
- 7API gateway service registration for Kong, Ambassador, or Istio gateways
Prerequisites
- Minimum 1.5GB RAM total (512MB per consul-server node recommended)
- Docker Engine 20.10+ with Docker Compose v2 support
- Available ports 8500 (HTTP API/UI) and 8600 (DNS) on the host system
- Understanding of distributed systems concepts like consensus and leader election
- Knowledge of service discovery patterns and health check configurations
- Network connectivity between all cluster nodes for gossip protocol communication
For development & testing. Review security settings, change default credentials, and test thoroughly before production use. See Terms
docker-compose.yml
docker-compose.yml
1services: 2 consul-server1: 3 image: hashicorp/consul:latest4 container_name: consul-server15 command: agent -server -bootstrap-expect=3 -ui -client=0.0.0.0 -retry-join=consul-server2 -retry-join=consul-server36 environment: 7 - CONSUL_BIND_INTERFACE=eth08 volumes: 9 - consul-server1:/consul/data10 ports: 11 - "8500:8500"12 - "8600:8600/udp"13 networks: 14 - consul-network15 restart: unless-stopped1617 consul-server2: 18 image: hashicorp/consul:latest19 container_name: consul-server220 command: agent -server -bootstrap-expect=3 -retry-join=consul-server1 -retry-join=consul-server321 environment: 22 - CONSUL_BIND_INTERFACE=eth023 volumes: 24 - consul-server2:/consul/data25 networks: 26 - consul-network27 restart: unless-stopped2829 consul-server3: 30 image: hashicorp/consul:latest31 container_name: consul-server332 command: agent -server -bootstrap-expect=3 -retry-join=consul-server1 -retry-join=consul-server233 environment: 34 - CONSUL_BIND_INTERFACE=eth035 volumes: 36 - consul-server3:/consul/data37 networks: 38 - consul-network39 restart: unless-stopped4041 consul-client: 42 image: hashicorp/consul:latest43 container_name: consul-client44 command: agent -retry-join=consul-server145 environment: 46 - CONSUL_BIND_INTERFACE=eth047 volumes: 48 - consul-client:/consul/data49 networks: 50 - consul-network51 restart: unless-stopped5253volumes: 54 consul-server1: 55 consul-server2: 56 consul-server3: 57 consul-client: 5859networks: 60 consul-network: 61 driver: bridge.env Template
.env
1# HashiCorp Consul Cluster2# 3-node server cluster with 1 clientUsage Notes
- 1Consul UI at http://localhost:8500
- 23-node HA cluster
- 3Register services via API or config
- 4DNS interface at :8600
- 5Health checking built-in
Individual Services(4 services)
Copy individual services to mix and match with your existing compose files.
consul-server1
consul-server1:
image: hashicorp/consul:latest
container_name: consul-server1
command: agent -server -bootstrap-expect=3 -ui -client=0.0.0.0 -retry-join=consul-server2 -retry-join=consul-server3
environment:
- CONSUL_BIND_INTERFACE=eth0
volumes:
- consul-server1:/consul/data
ports:
- "8500:8500"
- 8600:8600/udp
networks:
- consul-network
restart: unless-stopped
consul-server2
consul-server2:
image: hashicorp/consul:latest
container_name: consul-server2
command: agent -server -bootstrap-expect=3 -retry-join=consul-server1 -retry-join=consul-server3
environment:
- CONSUL_BIND_INTERFACE=eth0
volumes:
- consul-server2:/consul/data
networks:
- consul-network
restart: unless-stopped
consul-server3
consul-server3:
image: hashicorp/consul:latest
container_name: consul-server3
command: agent -server -bootstrap-expect=3 -retry-join=consul-server1 -retry-join=consul-server2
environment:
- CONSUL_BIND_INTERFACE=eth0
volumes:
- consul-server3:/consul/data
networks:
- consul-network
restart: unless-stopped
consul-client
consul-client:
image: hashicorp/consul:latest
container_name: consul-client
command: agent -retry-join=consul-server1
environment:
- CONSUL_BIND_INTERFACE=eth0
volumes:
- consul-client:/consul/data
networks:
- consul-network
restart: unless-stopped
Quick Start
terminal
1# 1. Create the compose file2cat > docker-compose.yml << 'EOF'3services:4 consul-server1:5 image: hashicorp/consul:latest6 container_name: consul-server17 command: agent -server -bootstrap-expect=3 -ui -client=0.0.0.0 -retry-join=consul-server2 -retry-join=consul-server38 environment:9 - CONSUL_BIND_INTERFACE=eth010 volumes:11 - consul-server1:/consul/data12 ports:13 - "8500:8500"14 - "8600:8600/udp"15 networks:16 - consul-network17 restart: unless-stopped1819 consul-server2:20 image: hashicorp/consul:latest21 container_name: consul-server222 command: agent -server -bootstrap-expect=3 -retry-join=consul-server1 -retry-join=consul-server323 environment:24 - CONSUL_BIND_INTERFACE=eth025 volumes:26 - consul-server2:/consul/data27 networks:28 - consul-network29 restart: unless-stopped3031 consul-server3:32 image: hashicorp/consul:latest33 container_name: consul-server334 command: agent -server -bootstrap-expect=3 -retry-join=consul-server1 -retry-join=consul-server235 environment:36 - CONSUL_BIND_INTERFACE=eth037 volumes:38 - consul-server3:/consul/data39 networks:40 - consul-network41 restart: unless-stopped4243 consul-client:44 image: hashicorp/consul:latest45 container_name: consul-client46 command: agent -retry-join=consul-server147 environment:48 - CONSUL_BIND_INTERFACE=eth049 volumes:50 - consul-client:/consul/data51 networks:52 - consul-network53 restart: unless-stopped5455volumes:56 consul-server1:57 consul-server2:58 consul-server3:59 consul-client:6061networks:62 consul-network:63 driver: bridge64EOF6566# 2. Create the .env file67cat > .env << 'EOF'68# HashiCorp Consul Cluster69# 3-node server cluster with 1 client70EOF7172# 3. Start the services73docker compose up -d7475# 4. View logs76docker compose logs -fOne-Liner
Run this command to download and set up the recipe in one step:
terminal
1curl -fsSL https://docker.recipes/api/recipes/hashicorp-consul/run | bashTroubleshooting
- Error 'No cluster leader': Ensure all three server nodes are running and can communicate on port 8300
- UI shows 'failed' health checks: Verify service definitions include proper health check endpoints and intervals
- Client cannot join cluster: Check that consul-client can resolve consul-server1 hostname via Docker networking
- Split-brain scenario after network partition: Restart minority nodes to rejoin the majority partition
- High memory usage on server nodes: Reduce log level or increase cleanup intervals in consul configuration
- Service registration fails with ACL errors: Ensure proper ACL tokens are configured if ACL system is enabled
Community Notes
Loading...
Loading notes...
Download Recipe Kit
Get all files in a ready-to-deploy package
Includes docker-compose.yml, .env template, README, and license
Components
consul-serverconsul-clientconsul-envoy
Tags
#service-mesh#consul#hashicorp#service-discovery#networking
Category
DevOps & CI/CDAd Space
Shortcuts: C CopyF FavoriteD Download