Project-4: ๐Ÿ”ข 11 Steps to Deploy a Web App using Docker Swarm on AWS: A Production-Ready Guide ๐Ÿš€๐Ÿณ

Project-4: ๐Ÿ”ข 11 Steps to Deploy a Web App using Docker Swarm on AWS: A Production-Ready Guide ๐Ÿš€๐Ÿณ

Day 83: #90DaysOfDevOps Challange

ยท

3 min read

In today's blog, we will explore the process of deploying a web application using Docker Swarm on AWS. Docker Swarm allows us to create a cluster of Docker nodes, making it easier to manage and scale our applications. Let's dive into the step-by-step process:

๐Ÿ”ธ Step 1: Create Instances

To begin, head over to the AWS portal and create three new instances: Swarm-manager, Swarm-worker1, and Swarm-worker2. These instances will form our Docker Swarm cluster.

๐Ÿ”ธ Step 2: Configure Inbound Rules

For each instance, you need to add the following rules to allow communication within the Docker Swarm:

  1. Custom TCP port 2377: This port is used by Docker Swarm for cluster management and communication between the swarm manager and worker nodes.

  2. Custom TCP port 8001 (or any other port you specified in your service): This port is specific to your application and allows external access to the service running inside the Docker containers.

๐Ÿ”ธ Step 3: Install Docker

Next, install Docker on all three nodes.

sudo apt-get update
sudo apt-get install docker.io -y

Docker installed on all three VMs ๐Ÿ˜‰

๐Ÿ”ธ Step 4: Initialize the Swarm

On the Swarm Manager node, open the terminal and run the command

sudo docker swarm init

This command will initialize an empty swarm.

๐Ÿ”ธ Step 5: Add Nodes to the Swarm

After initializing the swarm on the swarm-manager node, a key will be generated. Copy and run this key on the remaining servers to add them as workers to the swarm.

Node-1: Got an error then realized I need to use sudo

Node-2

Now! The family is complete! ๐Ÿ˜…

๐Ÿ”ธ Step 6: Check Swarm Nodes

To verify the status of all the nodes in the swarm manager, run the command:

sudo docker node ls

๐Ÿ”ธ Step 7: Create a Service

On the Manager Node, create a service using the command

sudo docker service create --name django-app-service --replicas 3 --publish 8001:8001 trainwithshubham/react-django-app:latest

๐Ÿ”ธ Step 8: Verify Service Deployment

Run below command to verify that the service has been created and is running.

sudo docker service ls

๐Ÿ”ธ Step 9: Check Container Status

To check the containers running on the manager node, use the below command :

sudo docker ps

๐Ÿ”ธ Step 10: Access the Web Application

The web application service will now be running on all three nodes. To access it, grab the IP address of any of the nodes followed by port 8001. For example, <ip_of_3_vms>:8001.

๐Ÿ”ธ Step 11: Removing Nodes

If you need to remove any node from the swarm, run below command on the specific worker node.

sudo docker swarm leave

This will remove the node from the swarm environment.

By following these steps, you can deploy your web application using Docker Swarm on AWS, ensuring a scalable and reliable production-ready environment. Docker Swarm simplifies the process of managing your application across multiple nodes, allowing for efficient scaling and high availability.

Feel free to share your experiences and ask any questions in the comments below. Happy deploying! ๐Ÿš€๐Ÿณ

#Docker #DockerSwarm #AWS #WebApplication #Deployment #Scalability #HighAvailability #DevOps

Did you find this article valuable?

Support Dhananjay Kulkarni by becoming a sponsor. Any amount is appreciated!

ย