Search code examples
consul

How to use Consul DNS for sending requests to a service


I've registered a service with Consul that I can connect to using localhost:8080, however I would like to send a request to Consul itself and then have that direct me to the service.

How do I find the Consul URL for my service to do this? The name of my service in the UI is dev-service-name-8080.


Solution

  • You can query the DNS interface on the local agent like so.

    dig @127.0.0.1 -p 8600 <name>.service.consul
    

    See https://learn.hashicorp.com/consul/getting-started/services#query-services for more info.