Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Docker Swarm on AWS Multiple AZ
#!/bin/sh
# Create consul container
export AWS_ACCESS_KEY_ID
export AWS_SECRET_ACCESS_KEY
export AWS_DEFAULT_REGION=ap-northeast-1
export AWS_ZONE=a
export AWS_SUBNET_ID
export AWS_INSTANCE_TYPE=c4.large
export AWS_SECURITY_GROUP
docker-machine --debug create --driver amazonec2 ec2-kvs
docker $(docker-machine config ec2-kvs) run -d -p 8500:8500 \
-h "consul" progrium/consul -server -bootstrap
# Create swarm-master container(zone: a)
export AWS_ZONE=a
export AWS_SUBNET_ID
docker-machine --debug create \
--driver amazonec2 \
--amazonec2-request-spot-instance \
--amazonec2-spot-price 0.03 \
--swarm --swarm-master \
--swarm-discovery="consul://$(docker-machine ip ec2-kvs):8500" \
--engine-opt="cluster-store=consul://$(docker-machine ip ec2-kvs):8500" \
--engine-opt="cluster-advertise=eth0:0" \
ec2-swarm
# Create swarm-slave container(zone: c)
export AWS_ZONE=c
export AWS_SUBNET_ID
docker-machine --debug create \
--driver amazonec2 \
--swarm \
--swarm-discovery="consul://$(docker-machine ip ec2-kvs):8500" \
--engine-opt="cluster-store=consul://$(docker-machine ip ec2-kvs):8500" \
--engine-opt="cluster-advertise=eth0:0" \
ec2-swarm-slave1
# Switch docker host to swarm-master
eval $(docker-machine env --swarm ec2-swarm)
# It does not work..
docker info
docker-machine rm ec2-swarm
docker-machine rm ec2-swarm-slave1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment