Docker Kata 002
>>> Stamp out Clusters
Where we’re going, we’re going to need clusters. Lots of clusters. A Groundhog Day’s worth of clusters.
So while we work out the whole Docker ecosystem, between services, DABs, loadbalancers, swarms, and the lot — let’s at least make it easy to create local clusters. I’m a big fan of local development environments, so here’s about 10 minutes of effort in creating a quick script that provisions a local, Virtualbox powered cluster that you can use to run some Docker Swarms.
It’s going to look a bit like a loop that creates some machines, and joins those machines to a Docker Swarm cluster. Here you go:
# This script is designed to get you up and running quickly with a Docker Swarm
# and Visualizer in order to run through <placeholder> exercise quickly.
# Docker Machine installed on your laptop
# Docker for Mac
# Set the machine names for later use in the script. You can change these if
# you require fresh machines
# Initialize Virtualbox machines using Docker Machine
for i in $master_node $node01_node $node02_node $node03_node; \
do docker-machine create -d virtualbox $i; done
# Create the Docker swarm
docker $(docker-machine config $master_node) swarm init \
--advertise-addr $(docker-machine ip $master_node):2377
# Add workers to the Docker Swarm
for i in $node01_node $node02_node $node03_node; \
do docker $(docker-machine config $i) swarm join \
--token `docker $(docker-machine config $master_node) swarm \
join-token worker -q` \
$(docker-machine ip $master_node):2377 ; done
echo "Your available machines:"
docker-machine ls -q
Spoiler alert: It’s a piece of shit. I bet one American dollar that someone could shrink this script down to 6 lines, in fact.
So leave a comment or better yet weigh in on the gist. I’ll be playing with Docker 1.12. Once you’ve perfected your version, post your suggestion in the comments or the gist, and let’s get to building services in Docker Kata 003.
Thanks for reading, and as ever — click the heart below if this helped.