Difficulty: Beginner
Estimated Time: 10 minutes

Created by Hashicorp, Consul solves the problem of service discovery and configuration for distributed, high availability applications.

Consul has four primary responsibilities:

  • Service Discovery: Locate where services, such as containers, are running within your cluster via a api or dns.

  • Key/Value Store: Use Consul as a highly available data store for data such as configuration details or feature switching.

  • Health Checking: Automatically route traffic away from unhealthy nodes.

  • Multi Datacentre: Out the box, Consul is data centre aware.

In this scenario, we'll use the official Docker image to launch a cluster of Consul agents. We'll then replace a node to indicate the health checking options via the command line and UI.

In this scenario, we explored how to launch a Consul cluster running as Docker containers. Once running, we simulated a node failure and how to identify the health via the CLI and UI.

In future scenarios, we'll explore how to Consul to manage API and DNS requests.

Launch Consul Cluster using Docker

Step 1 of 4

Start Agent

To start, we'll launch a primary Consul agent which others will connect too. Each of these agents will run as separate containers on the same node. In production, each of the containers would run on different machines.

The agents will form the initial cluster and Consul Quorum for ensuring data stored is consistent and remains available after outages.

Task: Launch Agent

To start an launch we use the official Docker image and provide the arguments agent -dev. To make the UI accessible we tell Consul to bind to the public IP instead of The UI runs on port 8500 which we map to the host.

docker run -d --name=c1 -p 8500:8500 consul agent -dev -client= -bind=

Because we haven't told this agent to join a cluster, it will create one for us. In the next step we'll add additional agents.