Running Docker Swarm(s) in docker on MAC !

A quick experiment to see if I can get multiple docker swarm clusters running as containers on mac using docker/dind !
First let's create a network to separate our clusters. Let's open a terminal and create 2 networks
$ docker network create my-swarm-net-1
$ docker network create my-swarm-net-2
Now open 2 or more terminals and run at least 1 manager node and 1 worker node
$ docker run -dit --privileged --network my-swarm-net-1 --name manager1 -d docker:dind
$ docker run -dit --privileged --network my-swarm-net-1 --name worker1 -d docker:dind
$ docker run -dit --privileged --network my-swarm-net-1 --name worker2 -d docker:dind
There should be 3 container running at this point
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
13f764da8e84 docker:dind "dockerd-entrypoin..." 30 seconds ago Up 28 seconds 2375/tcp worker2
ed082ef180c7 docker:dind "dockerd-entrypoin..." 38 seconds ago Up 37 seconds 2375/tcp worker1
889524715b87 docker:dind "dockerd-entrypoin..." About a minute ago Up 58 seconds 2375/tcp manager1
$
At this time, we should be ready to setup the cluster !
$ docker exec -it manager1 sh 
/ # docker swarm init
Swarm initialized: current node (jg47qfdu7wic6cgtrnt4gwhzy) is now a manager.

To add a worker to this swarm, run the following command:
To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.

/ # exit
Then on worker nodes
$ docker exec -it worker1 sh
/ # docker swarm join \
> --token SWMTKN-1-5regzvjce6yp8v153ad07a8qiwmwkiqmdr5ea8g7r3so8ciq2k-e8hxd7xfaqbsycy5a2o9i5kei \
> 172.21.0.2:2377
/ # exit
$ docker exec -it worker2 sh
/ # docker swarm join \
> --token SWMTKN-1-5regzvjce6yp8v153ad07a8qiwmwkiqmdr5ea8g7r3so8ciq2k-e8hxd7xfaqbsycy5a2o9i5kei \
> 172.21.0.2:2377
/ # exit
Let's verify !
$ docker exec -it manager1 docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS
bk5utfitnym1f2iquef65hpt1 ed082ef180c7 Ready Active
jg47qfdu7wic6cgtrnt4gwhzy * 1a0e2afd78bc Ready Active Leader
nm588gddb1jg8dnqirmiwjuvo 13f764da8e84 Ready Active
$


We can now create a second cluster, just make sure the container names are different and use preferably a different network !
Repeat the previous steps :
$ docker exec -it manager2 docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS
ggnulfyvftrtxcdc5cimxmm49 * d5b26b1e4299 Ready Active Leader
sjeifd1n5rrwdzjiyk98fm98k 76b9e549a625 Ready Active
utor4x1orblpjylkxso8xrb2z 8cb2610b6c5e Ready Active
$
Have fun !
One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.