# DevOps(Day-83):Container Harmony: Deploying a Resilient Web Application with Docker Swarm

![Deploying a Web Application on Docker Swarm - DEV Community](https://media.dev.to/cdn-cgi/image/width=1000,height=420,fit=cover,gravity=auto,format=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm9d4rl6umezr059b6z9y.PNG align="left")

Table of contents

Project Description

Pre-requisites

Project steps

## **Project Description**

The project aims to deploy a web application using Docker Swarm, a container orchestration tool that allows for easy management and scaling of containerized applications. The project will utilize Docker Swarm's production-ready features such as load balancing, rolling updates, and service discovery to ensure high availability and reliability of the web application. The project will involve creating a Dockerfile to package the application into a container and then deploying it onto a Swarm cluster. The Swarm cluster will be configured to provide automated failover, load balancing, and horizontal scaling to the application. The goal of the project is to demonstrate the benefits of Docker Swarm for deploying and managing containerized applications in production environments.

## **Pre-requisites**

1. Spin-up three servers in the AWS management console.
    
    Two servers are worker nodes and one server is manager mode.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1707804154309/aec3e804-ed78-40b5-ba49-7627129dbba4.png align="center")
    
    2. Install docker on all three servers.
        
    
    You can follow my previous blog for server spin-up and installing docker.
    
    ## **Project steps**
    
    1. Initialise the docker swarm in the manager node.
        
        To add a worker to this swarm, run the following command as displayed after the "**docker swarm init"** :
        
        **"docker swarm join --token SWMTKN-1-**sudo docker swarm join --token SWMTKN-1-4bm6mfcxa6ujfe6lgwth16iyki778ti51petunevyrrawefygd-ai0h58prd8fgjkg2dkfd359et 172.31.43.122:2377
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1707804406211/44dfcd77-03f1-4078-bc5c-037e0849be47.png align="center")
        
2. Open port **2377** in the security group for all the servers.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1707804468497/b58d6b47-35ed-4e2a-bd7c-802f8c20bfbb.png align="center")
    
3. Now join both worker nodes o the manager node.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1707804563215/71659e21-a943-4916-acb0-21cb8c9f9a7a.png align="center")
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1707804614091/c09c07ba-e6cf-4efa-846e-ce7dd7aece15.png align="center")
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1707804651241/5f38790c-771c-4703-8ec3-2cf76f52bc32.png align="center")
    
4. We can check the docker swarm status to check the connected worker nodes o manager nodes.
    
    **"docker node ls"**
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1707804720798/a526f8be-b592-4c8b-a57b-b9131b6517c7.png align="center")
    
5. Let's take an image from my repository to deploy the application on the docker swarm servers.
    
    The link to my DockerHub image is as follows:-
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1707804902649/c7d276e8-6e37-4392-9b8d-fc13a5311e5e.png align="center")
    
6. Create a service in the docker manager node server to install the application through the docker image from the docker hub.
    
    sudo docker service create --name django-app-service --replicas 3 --publish 8001:8001 trainwithshubham/react-django-app:latest
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1707804989891/e3681d0e-785d-4d27-a87c-667fe811c238.png align="center")
    
7. We can check the service that is created in the manager node server.
    
    Also, check the docker logs in the worker node servers for running docker containers.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1707805107812/b487d06e-1f8e-4bda-a05e-26472ead4362.png align="center")
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1707805145193/a664be1c-ab61-461d-9da3-736437ae673a.png align="center")
    
8. Let's check the web-app in both the swarm node servers.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1707805367912/69fa1418-14c8-4586-b2e6-2535d7bbdf4f.png align="center")
    
9. Let's check the web-app in both the swarm node servers.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1707805423432/5fbd4ecd-6adb-4980-9fc9-6df1801afb20.png align="center")
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1707805449345/1a0e23f8-473d-446b-a06e-0b40537f5295.png align="center")
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1707805498331/8b9e933c-2b4c-41d9-aee2-951986ea0e18.png align="center")
    
10. The application is running on both servers now.
    
    Thanks for reading my article. Have a nice day.
    
    Happy Learing ✨✨
