Consul
Discover services with Consul on Docker
This page provides an overview of Consul service discovery operations when running on Docker.
When running Consul on Docker, you can use the Consul DNS interface to perform service discovery operations.
Introduction
When a service registers with Consul, the catalog records the address of the container running the service. Consul then updates the service's catalog entry with the results of each health check it performs. Consul agents replicate catalog information between each other using the Raft consensus protocol, enabling high availability service networking through any Consul agent.
Consul's service discovery operations use Consul DNS addresses to route traffic to healthy service instances and return information about service nodes registered to Consul.
You can also use the docker exec
command to connect directly to a Consul container and interact with Consul's service discovery features.
Application load balancing
A load balancer accepts incoming traffic requests and routes them to service instances in a distributed network so that resource consumption is spread between available instances and individual nodes are not overworked. Consul functions as a load balancer by directing traffic to healthy service instances using information registered to the catalog and Consul DNS. Consul can also integrate with external load balancers such as NGINX and HAProxy.
Load balancing is a core component of Consul's service discovery functionality. For more information, refer to service discovery overview.
Static lookups
To lookup details about registered services and specific service instances, perform a static query using Consul DNS to return A and SRV records for your deployment. Consul DNS enables you to return results from across your Consul deployment, including the number of healthy instances and network addresses of nodes that match service names or custom tags.
Consul Enterprise enables static lookups for Enterprise features such as virtual services and sameness groups. Refer to Perform static DNS queries for more information.
Prepared queries
Prepared queries are configurations that enable you to register a complex service query and perform dynamic lookups on services using Consul DNS. Prepared queries enable advanced lookup scenarios such filtering by multiple tags and returning services that match a prefix. You can also use prepared queries to implement service failover scenarios between datacenters.
For more information, refer to Perform dynamic service lookups with prepared queries.
Reference documentation
For reference material related to Consul's service discovery functions on Docker, refer to the following pages:
Constraints, limitations, and troubleshooting
If you experience errors when using Consul's service discovery features, refer to the following list of technical constraints.
- Consul's DNS and service discovery features are enabled by default. When Consul service mesh is enabled, you can use an existing DNS such as CoreDNS by configuring Consul's transparent proxy. Refer to transparent proxy for more information.
- When Consul's service mesh is enabled, you can use configuration entries that have additional impacts on Consul's service discovery behavior:
- You can customize Consul's load balancing policy using a service resolver configuration entry.
- You can adjust the request rate for services using a service defaults configuration entry.