Skip to content

Instantly share code, notes, and snippets.

@fquffio
Last active December 9, 2015 11:58
Show Gist options
  • Save fquffio/162588a9f19ea83822c8 to your computer and use it in GitHub Desktop.
Save fquffio/162588a9f19ea83822c8 to your computer and use it in GitHub Desktop.
Create a Docker swarm with one master node and a variable amount of slave nodes using a Consul discovery service.
###
# Create a swarm cluster
###
SWARM_NODES_COUNT=2
# Create a Consul discovery container on `default` Docker machine
docker run -d --name swarm-consul \
--restart=always \
-p "8500:8500" \
-h "consul" \
progrium/consul -server -bootstrap
# Create the swarm master
docker-machine create \
-d virtualbox \
--swarm --swarm-master \
--swarm-discovery="consul://$(docker-machine ip default):8500" \
--engine-opt="cluster-store=consul://$(docker-machine ip default):8500" \
--engine-opt="cluster-advertise=eth1:2376" swarm-master
# Create the swarm nodes
for (( i=1; i<=$SWARM_NODES_COUNT; i++ )); do
docker-machine create \
-d virtualbox \
--swarm \
--swarm-discovery="consul://$(docker-machine ip default):8500" \
--engine-opt="cluster-store=consul://$(docker-machine ip default):8500" \
--engine-opt="cluster-advertise=eth1:2376" swarm-node0$i
done
# Connect to the swarm master
eval $(docker-machine env --swarm swarm-master)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment