Forked from nishanttotla/swarm-with-docker-machine.sh
Created
February 11, 2016 22:21
-
-
Save jmshal/e3d1b5dba30dbeca7528 to your computer and use it in GitHub Desktop.
A bash script to set up a simple Docker Swarm cluster using Docker Machine
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################################## INSTRUCTIONS ################################## | |
# 1. Make sure docker-machine is installed on your machine # | |
# 2. Download the file # | |
# 3. Run using $ . swarm-with-docker-machine.sh so that DOCKER_HOST is exported # | |
################################################################################## | |
# Clean any existing machines | |
yes | docker-machine rm manager | |
yes | docker-machine rm agent1 | |
yes | docker-machine rm agent2 | |
# Create machines | |
docker-machine create -d virtualbox manager | |
docker-machine create -d virtualbox agent1 | |
docker-machine create -d virtualbox agent2 | |
# Get Swarm token | |
eval $(docker-machine env manager) | |
docker pull swarm | |
TOKEN="$(docker run --rm swarm create)" | |
# Run Swarm manager | |
docker run -d -p 3376:3376 -t -v /var/lib/boot2docker:/certs:ro swarm manage -H 0.0.0.0:3376 --tlsverify --tlscacert=/certs/ca.pem --tlscert=/certs/server.pem --tlskey=/certs/server-key.pem token://$TOKEN | |
# Join Swarm agents | |
eval $(docker-machine env agent1) | |
docker run -d swarm join --addr=$(docker-machine ip agent1):2376 token://$TOKEN | |
eval $(docker-machine env agent2) | |
docker run -d swarm join --addr=$(docker-machine ip agent2):2376 token://$TOKEN | |
# Manage the Swarm | |
export DOCKER_HOST=$(docker-machine ip manager):3376 | |
# Now run Docker commands to play with your Swarm |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment