Docker Swarm Cluster using Consul

Docker Swarm is native clustering for Docker. It allows you create and access to a pool of Docker hosts using the full suite of Docker tools. Because Docker Swarm serves the standard Docker API, any tool that already communicates with a Docker daemon can use Swarm to transparently scale to multiple hosts.

Docker Swarm Logo Consul Logo

Docker Swarm has a Manager, a pre-defined Docker Host, and is a single point for all administration. Swarm manager orchestrates and schedules containers on the entire cluster, and can be configured in High Availability. The containers are deployed on Nodes that are additional Docker Hosts.

Swarm talks to a hosted Discovery Service that maintains a list of IPs in your cluster. For development, its easy to use the default discovery service hosted on Docker Hub. Complete instructions for that are available in Install and Create Docker Swarm. This blog will show how to setup Docker Swarm Cluster using Consul.

Lets get started!

Create Consul Discovery Service

  1. Create a Machine that will host discovery service:
  2. Connect to this Machine:
  3. Run Consul service using the following Compose file:
    This file is also available at github.com/arun-gupta/docker-images/tree/master/consul.

    The service is started as:

    Started container can be verified as:

Create Docker Swarm Cluster using Consul

Swarm is fully integrated with Machine, and so is the easiest way to get started.

  1. Create a Swarm Master using the Consul discovery service:
    Three options to look here:

    • --swarm-discovery defines address of the discovery service
    • --cluster-advertise advertise the machine on the network
    • --cluster-store designate a distributed k/v storage backend for the cluster

    In addition, --swarm configures the Machine with Swarm, --swarm-master configures the created Machine to be Swarm master.

  2. Connect to this newly created master and find some information about it:

    This will show the output as:

  3. Create a new Machine to be part of this Swarm cluster:

    Machine talks to the Discovery Service using --swarm-discovery.

  4. Create a second node in this cluster:

  5. List all the created Machines:

    The machines that are part of the cluster have cluster’s name in the SWARM column, blank otherwise. For example, “default” and “consul-machine” are standalone machines where as all other machines are part of the “swarm-master” cluster. The Swarm master is also identified by (master) in the SWARM column.

  6. Connect to the Swarm cluster and find some information about it:

    The main difference here is --swarm when finding information about Swarm cluster as opposed to a single Machine.

    This shows the output as:

    There are 3 nodes – one Swarm master and 2 Swarm _worker_ nodes. There is a total of 4 containers running in this cluster – one Swarm agent on master and each node, and there is an additional swarm-agent-master running on the master. This can be verified by connecting to the master and listing all the containers.

  7. List nodes in the cluster with the following command:

Subsequent blog will explain how to deploy applications to this Docker Swarm Cluster.

Enjoy!

 

Be Sociable, Share!
  • Tweet

14 thoughts on “Docker Swarm Cluster using Consul

  1. Thank you Arun! Very interesting and useful. Could you include in the future any method for load balancing in Swarm, please? Regards.

  2. Pingback: Docker Swarm Cluster using Consul | Dinesh Ram Kali.
  3. Laurent,

    Here is a possible way: https://www.digitalocean.com/community/tutorials/how-to-configure-consul-in-a-production-environment-on-ubuntu-14-04

  4. Hi Arun,

    I’m wondering if you are available for consultation on Docker, or a quick remote call, on Docker Swarm Cluster concept and deployment.

    cheers.

  5. Is it possible to run the consul server on the swarm master ?

    I’m going to have a very small cluster, as cheap as possible, and would rather not have an extra box just running Consul.

  6. Pingback: Working Sample to try out Docker Swarm on Windows 10 – My personal blog
  7. Pingback: We're not gonna link. We can't link, Bendis. You know why? Because we are so very pretty. We are just too pretty for God to let us link - Magnus Udbjørg
  8. You should definitely check https://essaydragon.com/blog/paraphrasing-tools out if you want to know more about paraphrasing tools. I had such experience so I know what I am talking about

  9. If you are thinking of ordering thread answering help, choose this writing service https://specialessays.com/write-my-discussion-board-post/

Leave a Reply

Your email address will not be published. Required fields are marked *