Create a Docker 1.12 Swarm cluster on AWS
This gist will drive you through creating a Docker 1.12 Swarm cluster (with Swarm mode) on your machine in Virtualbox.
You need a few things already prepared in order to get started. You need at least Docker 1.12 set up. I was using the stable version of Docker for mac for preparing this guide.
$ docker --version
Docker version 1.12.0, build 8eab29e
You also need Docker machine installed.
$ docker-machine --version
docker-machine version 0.8.0, build b85aac1
$ docker-machine create --driver virtualbox vizdemo-manager
$ docker-machine create --driver virtualbox vizdemo-worker1
$ docker-machine create --driver virtualbox vizdemo-worker2
$ docker-machine ip vizdemo-manager
192.168.99.110
$ eval $(docker-machine env vizdemo-manager)
$ docker swarm init --advertise-addr 192.168.99.110 --listen-addr 192.168.99.110:2377 # Use the IP of the vizdemo-manager node here
This should output a command which you can use to join on the workers. You will need this in a minute.
worker1
to the swarm.
First you need the IP address with docker-machine ip vizdemo-worker1
(192.168.99.108
for me). Then, you should point your docker client to the right node with eval $(docker-machine env vizdemo-worker1)
. Use the command in the output of swarm init
to join the worker. Don't forget to add the --listen-addr
parameter.$ docker swarm join --token TOKEN --listen-addr 192.168.99.108:2377 192.168.99.110:2377
worker2
.
First you need the IP address with docker-machine ip vizdemo-worker2
(192.168.99.109
for me). Then, you should point your docker client to the right node with eval $(docker-machine env vizdemo-worker2)
. Use the command in the output of swarm init
to join the worker. Don't forget to add the --listen-addr
parameter.$ docker swarm join --token TOKEN --listen-addr 192.168.99.109:2377 192.168.99.110:2377
$ eval $(docker-machine env vizdemo-manager)
$ docker node ls
You are done. Enjoy!
This gist will drive you through creating a Docker 1.12 Swarm cluster (with Swarm mode) on AWS infrastructure.
You need a few things already prepared in order to get started. You need at least Docker 1.12 set up. I was using the stable version of Docker for mac for preparing this guide.
$ docker --version
Docker version 1.12.0, build 8eab29e
You also need Docker machine installed.
$ docker-machine --version
docker-machine version 0.8.0, build b85aac1
You need an AWS account. Either you should have you credentials
file filled:
$ cat ~/.aws/credentials
[default]
aws_access_key_id =
aws_secret_access_key =
Or you need to export these variables before going forward.
$ export AWS_ACCESS_KEY_ID=
$ export AWS_SECRET_ACCESS_KEY=
Also, you should have AWS CLI installed.
$ aws --version
aws-cli/1.10.44 Python/2.7.10 Darwin/15.5.0 botocore/1.4.34
You should collect the following details from your AWS account.
$ VPC=vpc-abcd1234 # the VPC to create your nodes in
$ REGION=eu-west-1 # the region to use
$ SUBNET=subnet-abcd1234 # the subnet to attach your nodes
$ ZONE=b # the zone to use
Execute these steps one by one. We will create three t2.micro nodes. NOTE: this might cost you some money.
$ docker-machine create -d amazonec2 --amazonec2-vpc-id $VPC --amazonec2-region $REGION --amazonec2-zone $ZONE --amazonec2-instance-type t2.micro --amazonec2-subnet-id $SUBNET --amazonec2-security-group demo-swarm demo-swarm-manager
$ docker-machine create -d amazonec2 --amazonec2-vpc-id $VPC --amazonec2-region $REGION --amazonec2-zone $ZONE --amazonec2-instance-type t2.micro --amazonec2-subnet-id $SUBNET --amazonec2-security-group demo-swarm demo-swarm-node1
$ docker-machine create -d amazonec2 --amazonec2-vpc-id $VPC --amazonec2-region $REGION --amazonec2-zone $ZONE --amazonec2-instance-type t2.micro --amazonec2-subnet-id $SUBNET --amazonec2-security-group demo-swarm demo-swarm-node2
$ docker-machine ssh demo-swarm-manager ifconfig eth0
This should output a bunch of details, but somewhere in the second row you should have the IP address. In my case it is 10.0.0.22
$ eval $(docker-machine env demo-swarm-manager)
$ docker swarm init --advertise-addr 10.0.0.22 # This is the internal IP of manager node.
This should output a command which you can use to join on the workers. You will need this in a minute.
$ aws ec2 describe-security-groups --filter "Name=group-name,Values=demo-swarm"
From this command you should get all the details of the security group. Including the GroupId. Copy that information and run the following commands:
$ SECURITY_GROUP_ID=sg- #Copy the group id here
$ aws ec2 authorize-security-group-ingress --group-id $SECURITY_GROUP_ID --protocol tcp --port 2377 --source-group $SECURITY_GROUP_ID
aws ec2 authorize-security-group-ingress --group-id $SECURITY_GROUP_ID --protocol tcp --port 7946 --source-group $SECURITY_GROUP_ID
aws ec2 authorize-security-group-ingress --group-id $SECURITY_GROUP_ID --protocol udp --port 7946 --source-group $SECURITY_GROUP_ID
aws ec2 authorize-security-group-ingress --group-id $SECURITY_GROUP_ID --protocol tcp --port 4789 --source-group $SECURITY_GROUP_ID
aws ec2 authorize-security-group-ingress --group-id $SECURITY_GROUP_ID --protocol udp --port 4789 --source-group $SECURITY_GROUP_ID
$ eval $(docker-machine env demo-swarm-node1)
$ docker swarm join --token TOKEN 10.0.0.22:2377 # This is the command copied from docker swarm init command's output
$ eval $(docker-machine env demo-swarm-node2)
$ docker swarm join --token TOKEN 10.0.0.22:2377 # This is the command copied from docker swarm init command's output
$ eval $(docker-machine env vizdemo-manager)
$ docker node ls
You are done. Enjoy!