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
dockerrun-d-pβ€œ8400:8400”-pβ€œ8500:8500”-hβ€œconsul”russmckendrick/consul

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
dsdsdsoβ€”β€”β€”β€”β€”eoβ€”β€”β€”β€”β€”eoβ€”β€”β€”β€”β€”ecrcrcrkdddddvkdddddvkdddddveriiiiieriiiiieriiiiiriggggcriggggcriggggc-viiiie-viiiie-viiiiemetttt-metttt-metttt-araaaadaraaaadaraaaadcllllicllllicllllihdooooshdooooshdoooosiiccccciiccccciicccccngeeeeongeeeeongeeeeoeiaaaaveiaaaaveiaaaavtnnnnetnnnnetnnnneca----rca----rca----rrlarspyrlarspyrlarspyeoceir0eoceir0eoceir0accgzi1accgzi2accgzi3teeievteeievteeieveasoaeasoaeasoansn5tnsn5tnsn5t-1e-1e-1etl2-tl2-tl2-omnomnomnknbeknbeknbee1te1te1tnwnwnw\\\yryryrokokokuiuiuirnrnrn-g-g-gdddi\i\i\gggiiitttaaalll---oooccceeeaaannn---aaapppiii---tttoookkkeeennn---gggoooeeesss---hhheeerrreee\\\

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
SSSDDD123===$$$(((dddoooccckkkeeerrr---mmmaaaccchhhiiinnneeesssssshhhssseeerrrvvviiiccceee---dddiiissscccooovvveeerrryyy000123β€œβ€œβ€œiiipppaaaddddddrrrssshhhooowwweeettthhh111gggrrreeeppp---PPPoooβ€˜β€˜β€˜iiinnneeettt\\\KKK[[[\\\ddd...]]]+++’’’”””)))

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
d----------roppppppppphβ€”ucskβ€œβ€œβ€œβ€œβ€œβ€œβ€œβ€œβ€œβ€œnse$$$$$$$$$camrSSSSSS(SSomcDDDDDDdDDnek$111111o11s=e(::::::c::u”nd888888k88lcdo333345e660orc000000r001nik011200-00”sce::::::m::ukr888888a88\l/-333345c660cm000000h001oa011200i00"nc””/”””n”/shueu\ui\\d\\\\dlnpipe”p”agc\s\eoennrtfvii-gcdeas-tedari-vsdicicorev-e/drdiyas0tc1ao)v:-e8sr5ey0r00v1:e)8r5r0-u0bn”oo-\tdst\rap-expect3-ui-dir/ui-client=0.0.0.0-advertise=$SD1

then onservice-discovery02;

Consul Docker Cluster 5/10
d----------roppppppppphβ€”ucskβ€œβ€œβ€œβ€œβ€œβ€œβ€œβ€œβ€œβ€œnse$$$$$$$$$camrSSSSSS(SSomcDDDDDDdDDnek$222222o22s=e(::::::c::u”nd888888k88lcdo333345e660orc000000r002nik011200-00”sce::::::m::ukr888888a88\l/-333345c660cm000000h002oa011200i00"nc””/”””n”/shueu\ui\\d\\\\dlnpipe”p”agc\s\eoennrtfvii-gcdeas-tedari-vsdicicorev-e/drdiyas0tc2ao)v:-e8sr5ey0r00v2:e)8r5r0-u0bn”oo-\tdst\rap-expect3-ui-dir/ui-client=0.0.0.0-advertise=$SD2

and finally on service-discovery03;

Consul Docker Cluster 6/10
d----------roppppppppphβ€”ucskβ€œβ€œβ€œβ€œβ€œβ€œβ€œβ€œβ€œβ€œnse$$$$$$$$$camrSSSSSS(SSomcDDDDDDdDDnek$333333o33s=e(::::::c::u”nd888888k88lcdo333345e660orc000000r003nik011200-00”sce::::::m::ukr888888a88\l/-333345c660cm000000h003oa011200i00"nc””/”””n”/shueu\ui\\d\\\\dlnpipe”p”agc\s\eoennrtfvii-gcdeas-tedari-vsdicicorev-e/drdiyas0tc3ao)v:-e8sr5ey0r00v3:e)8r5r0-u0bn”oo-\tdst\rap-expect3-ui-dir/ui-client=0.0.0.0-advertise=$SD3

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
docker$(docker-machineconfigservice-discovery01)execconsul01consuljoin$SD1$SD2$SD3

I then checked the logs onservice-discovery01by running;

Consul Docker Cluster 8/10
docker$(docker-machineconfigservice-discovery01)logsconsul01

Should show you something like;

Consul Docker Cluster 9/10
====NDSCCGA=2222222222222222222222====oaellot=0000000000000000000000>>>>dtriusl>1111111111111111111111eavessa6666666666666666666666WSSCcentisL//////////////////////Attonertep:o0000000000000000000000Raanan:rg2222222222222222222222NrrsmtAe//////////////////////IttueetdAnd2222222222222222222222Niil:rrddca7777777777777777777777Gnn:urdrt:ggaβ€˜e:rya1111111111111111111111gcβ€˜:p7777777777777777777777ECCeod(0tw::::::::::::::::::::::xoonncb.1:i0000000000000000000000pnnts1o00l7777777888889999999999essu’o..fl::::::::::::::::::::::cuurlt01a5555555012450000000000tllu0s.3ln0000002929101111111112n1t01soMaan’r.ew[[[[[[[[[[[[[[[[[[[[[[oggia(5,IIIIIEWEEEEEIIIIIIIIIIdeenpH.sNNNNNRARRRRRNNNNNNNNNNenng:T9RtFFFFFRRRRRRRFFFFFFFFFFtt!T8PrOOOOO]N]]]]]OOOOOOOOOOe…fPCe]]]]]]]]]]]]]]]]nRa:(-aaaaaaaaPlLTmssrccgrgggggaascsacccabCs8ALeeaooeaeeeeeggeoegooogl…e5NSirrfnnnfnnnnneernrennnee)0::nfftsstttttttnnfsfnsssnd0:::uu:::::::tt:u:tuuut,,8fall.:l:lll:3asEEN::fEfcfcfrE:E:::eH0lvvoanaoaoap(vv(SxT1sieedaaiaioioicLeaeLaANypT,etnneddlblrlrl:AndnAdteneP,ttddelededeNtdtNdtwccSWoMMaiidedididA)MiM)ieet:ATceetnnSnncenenmldiNLcmmggtitatatcjmgmjgpen-:Subb1onototoeobbotasg1-ree0LWgeepieLeiLide,8Isrr.AAslssstnrArnAner33n:JJ1NNyeyuyuyeiJNJeNgrvD0coo3nNnpnpndnoodisN2oii1sscocdcdcgisi:sbeceS)mnn.eedaac:neneoler:i::5rrrertrtrl:r:3roevn.vveeeeeei[vvtcβ€˜e8gcc9eemdmmme1cecEestcr6:oo8rroioeoeon0ororrteos0nn:tstrtrtt.nnrrdn0fss8cceaerere:1scs:ca:s,auu3ooboo3uouopulll0nnslsrsrs11lnlnclRs000sstet:t:t2.0s0swo’Pe11uuadaaa752u3uinC.[llt,tNtNt..llts:1dF00eeoeoe091010hu0co11:a:::.80203l8.1l.ncc0..n041l(dNdNlNlN.11(1(o3031oAcoououo103A3Ad010wd1nss:.1d1de)..edcoctctc41.d.ds51rr(llelel434r9r:.3]:Aukururu21.:.:91dsnsss3.81[8.e1dtotltlt44010115n0reweeeee.0600.t.:rnrarar8...9e1dd01118r31lplelel333i10eeerere1111n..aeaaa0...g51drddd.494.3eseee1...F91r.rrr3818o8.1000l:5A.:6:l8.b98:8o39o.383w08r1030e0:t0000r)8i6)03n])1s(0g(0tD0D(.aC)eCD1t:l:C3e(e:1dDcd.cCtcd91:i1c.)o)11dn)0c.61:)830010.131.5.98:8300]

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
openhttp://$(docker-machineipservice-discovery01):8500/ui

and as expected I had three hosts within my cluster all on the shared private networking IP;

consul

Bosh!