February 27, 2016 Β· 23 min Β· Russ Mckendrick | Suggest Changes
As mentioned in my previous post I have been doing a lot of work with Docker Machineβand Docker Swarmβrecently, to configure mulit-host networking with the latest version of Docker I needed to use a service discovery tool. As I had played with Consulβin the past I decided to use that for my back-end service discovery.
Now if I wanted to launch a single node then I would run the following;
Consul Docker Cluster 1/10
However, thats not really recommended so here is how you stat a cluster using the same imageβ. First of all, I launched three hosts in Digital Oceanβwith shared private networking enabled using Docker Machine;
Consul Docker Cluster 2/10
As Docker Machine only returns the primary IP address when you run docker-machine ip machine-name I needed to grab the shared private IP addresses for each of the three hosts and put them in an environment variable as I would be using them several times;
Consul Docker Cluster 3/10
Now I had the hosts up and also the shared private IP addresses of the three hosts it was time to launch the three Consul nodes;
First on service-discovery01;
Consul Docker Cluster 4/10
then onservice-discovery02;
Consul Docker Cluster 5/10
and finally on service-discovery03;
Consul Docker Cluster 6/10
As you can see, there are a lot of port which need to be published for the clustering to work, including ones on UDP. This is the reason for launching usingDigital Oceanβsβshare private networking. I could have took it one step further and properly locked each of the three hosts down further so they could only talk with each other, but thats for another time.
The other thing to note is that I am telling Consul to advertise it is running on the shared private networking IP address, if I didnβt then Consul would default to advertising the IP address of the container.
This means that while nodes would be registering themselves correctly they would not be able to contact each other as we have not enabled any sort of Docker multi-host networking for the service discovery nodes. Again, I could if I wanted to by using something likeWeave, but that would add additional steps to these already long notes.
Now that the three Consul nodes have been launched I created the cluster by running the following command against Consul onservice-discovery01;
Consul Docker Cluster 7/10
I then checked the logs onservice-discovery01by running;
Consul Docker Cluster 8/10
Should show you something like;
Consul Docker Cluster 9/10
Finally, as the image has theConsul UIβenabled, I could view my cluster in my browser by opening service-discovery01βs IP;
Consul Docker Cluster 10/10
and as expected I had three hosts within my cluster all on the shared private networking IP;