Setting Up Docker Swarm on Amazon EC2

This post would give you basic idea on Docker Swarm and AWS EC2. Please follow the steps.

Step 1. Setup a EC2 instances using AWS management console.

1.1 Create an EC2 instance(free tier, ofcourse) using management console.

1.2 On AWS console, create EC2 Template from the instance – as you will need atleast 4 EC2 instances to run an ideal minimum Docker Swarm of 3 managers and 1 worker nodes.

1.3 Spawn 3 more instances from saved Template.

1.4 Update Security Group to allow TCP and UDP traffic within the Subnet. Security group at my end looks like below.

Step 2. Setup Docker on EC2 instances

2.1 Setup Docker on your EC2 by running below command on Cmd prompt or Terminal window connected to your EC2 instance and then setup the priviledges.

sudo yum install -v docker

sudo usermod -a -G docker ec2-user

2.2 Lets start the Docker and validate If Its running fine.

sudo service docker start

ps -A | grep docker →this command should return atleast 2 results.

Docker Info →If this command fails to show your docker information, as it happened with me, just restart your EC2 instance.

2.3 Repeat the steps 2.1 and 2.2 on other 3 EC2 instances.

Step 3. Setup Docker Swarm

Swarm is a Docker cluster with managers and worker nodes. Lets setup this swarm with 3 manager and 1 worker nodes. This may sounds familiar arrangement for ones who work in matrix reporting teams 🙂

3.1 Start a Docker swarm on one of the EC2 instances, which by default will make that node as Manager Leader.

Docker swarm init

3.2 Echo manager and worker certificate public keys by running below commands. Below commands will also spit the actual commands that you can run to have other EC2 instances to join as manager or worker(step 3.3)

Docker swarm join-token manager

Docker swarm join-token worker

3.3 Join other Ec2 instances as manager or worker.

Docker swarm join –token <token> <leader-ip:port>

3.4 Docker Swarm is ready with 3 managers and 1 worker nodes. Below command will give you the details of your swarm.

docker swarm node ls

Author: Aditya Bhuyan

I am an IT Professional with close to two decades of experience. I mostly work in open source application development and cloud technologies. I have expertise in Java, Spring and Cloud Foundry.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s