Hello Docker Swarm with SwarmKit

TLDR; It’s not what swarm you looking for, LOL

🐳 Jump into a swarm and get lost! This should be fun!


We’ll install SwarmKit on Mac OSX ELCapitan, we’ll require installed go-lang (No worry it’s my first time for go-lang too). Do run it and grab some coffee, this will take a while.

Pro tip : you can also try go lang with Docker approach if you feeling brave.

You should see.


Create node-1

Open new terminal and…

swarmd -d /tmp/node-1 --listen-control-api /tmp/manager1/swarm.sock --hostname node-1

Create node-2

Another terminal and…

swarmd -d /tmp/node-2 --hostname node-2 --join-addr

Create node-3

We can do this all day! Another terminal!

swarmd -d /tmp/node-3 --hostname node-3 --join-addr

List nodes

Summon another terminal, This is why we need 4K screen.

$ export SWARM_SOCKET=/tmp/manager1/swarm.sock
$ swarmctl node ls

Start a redis service

$ swarmctl service create --name redis --image redis:3.0.5

List the running services

$ swarmctl service ls

Inspect the service

$ swarmctl service inspect redis

Updating Services

We can scale the service by changing the instance count:

$ swarmctl service update redis --replicas 6

Inspect the service

$ swarmctl service inspect redis

Or upgrade image from redis:3.0.5 to redis:3.0.6

$ swarmctl service update redis --image redis:3.0.6

Inspect the service

$ swarmctl service inspect redis

And you should see something like this


We can use SwarmKit to monitor node health. When failures, it re-schedules tasks to other nodes! How cool is that!

Put node-1 into maintenance mode

$ swarmctl node drain node-1

List current node

$ swarmctl node ls

Inspect redis

$ swarmctl service inspect redis

You should get…

Poor node-1

As you can see node-1 is drain and node-2, node-3 is get it cover! Great job node-2, node-3! Don’t work too hard guys. :D

BTW, This is not a usual way to get into the swarm, because SwarmKit is not for ordinary user! Refer to Docker Engine 1.12 Swarm Tutorials

The cluster management and orchestration features embedded in the Docker Engine are built using SwarmKit. Engines participating in a cluster are running in swarm mode.

I found that only concept is relevant there but some commands still different. And somehow…

$ docker service inspect redis

Will return…

Error: no such service: redis

Bummer! We’re doing it wrong! We should get out of this swarm ASAP. LOL

Next swarm diving, I’ll try usual approach with minimal prerequisites as possible. And ship it to DigitalOcean pretty much later.

Note (ref)

Don’t miss a chance to get free $10 for DigitalOcean ← 2 months free hosting!
And do claim your cheapest .io name before it gone at NameCheap.

Happy Swarming!