Skip to content

Instantly share code, notes, and snippets.

@Mierdin
Last active February 1, 2016 21:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mierdin/a1d803f501bd34137517 to your computer and use it in GitHub Desktop.
Save Mierdin/a1d803f501bd34137517 to your computer and use it in GitHub Desktop.
A quick script to create a Swarm cluster with Docker Machine on OSX (with configuration for multi-host networking as well)
# Create
docker-machine create -d virtualbox local
eval "$(docker-machine env local)"
TOKEN_SWARM=$(docker run swarm create)
docker-machine create -d virtualbox mh-keystore
docker $(docker-machine config mh-keystore) run -d -p "8500:8500" -h "consul" progrium/consul -server -bootstrap
CREATE_MASTER_NODE="docker-machine create --engine-opt="cluster-advertise=eth1:2376" --engine-opt="cluster-store=consul://$(docker-machine ip mh-keystore):8500" -d virtualbox --swarm --swarm-master --swarm-discovery token://$TOKEN_SWARM swarm-master"
CREATE_NODE_01="docker-machine create --engine-label name=swarm-agent-00 --engine-label storage=ssd --engine-opt="cluster-advertise=eth1:2376" --engine-opt="cluster-store=consul://$(docker-machine ip mh-keystore):8500" -d virtualbox --swarm --swarm-discovery token://$TOKEN_SWARM swarm-agent-00"
CREATE_NODE_02="docker-machine create --engine-label name=swarm-agent-01 --engine-label storage=rust --engine-opt="cluster-advertise=eth1:2376" --engine-opt="cluster-store=consul://$(docker-machine ip mh-keystore):8500" -d virtualbox --swarm --swarm-discovery token://$TOKEN_SWARM swarm-agent-01"
eval $CREATE_MASTER_NODE
eval $CREATE_NODE_01
eval $CREATE_NODE_02
eval $(docker-machine env --swarm swarm-master)
# Destroy
# WARNING - THESE COMMANDS ASSUME THAT THIS IS YOUR ONLY USE FOR DOCKER MACHINE.
# IT WILL DELETE ALL DOCKER MACHINES THAT YOU HAVE PROVISIONED.
# (BUT YOU OF COURSE ARE NOT JUST IMPLICITLY RUNNING COMMANDS YOU FOUND ON THE INTERNET...RIGHT?)
# docker-machine kill $(docker-machine ls -q)
# docker-machine rm -y $(docker-machine ls -q)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment