# Project : Containerize and Scale: Deploying Web Apps with Docker Swarm

Objective: Discover the power of Docker Swarm, a versatile container orchestration tool, to deploy web applications with remarkable scalability, reliability, and high availability. This project showcases the seamless management and automated failover features that Docker Swarm offers, making it an ideal choice for production environments with containerized applications.

Step 1 : Create 3 EC2 instances.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690517635033/8aaf7e9f-2d5f-4a5d-a2a4-95a637bc2e0f.png align="center")

Ensure that ports 2377 and 8000 are open for incoming traffic.

Step 2 : Install Docker on all instances.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690518219066/2a9ef17e-1a84-4a98-a65a-c4b5319451fd.png align="center")

Step 3 : Initialize Docker Swarm on the "swarm-manager" instance with the following command:

```bash
docker swarm init
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690518334960/a74074dd-39ac-4c59-b1d0-8fe62daa16f0.png align="center")

Step 4 : After initializing the swarm on the "swarm-manager" node, a key will be generated to add other nodes as workers. Copy and run that key on the rest of the servers.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690518515559/ac88bf4c-af89-43d7-bccc-7cb22d273d2d.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690518557873/f19be307-67a5-4ebc-a671-f0988e4e2441.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690518580308/cff2aa28-f167-4f6e-89a2-c0320dc914a1.png align="center")

Step 5 : To check all the nodes in the manager, use the following command:

```bash
docker node ls
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690518738761/219fd52a-a11f-43c2-920b-36b284f81f0a.png align="center")

Step 6 : Create a service on the Manager node with this code:

```bash
sudo docker service create --name node-app-service --replicas 3 --publish 8000:8000 patelajay745/node-app-new:latest
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690519147463/c77d73b4-7768-4cec-af03-75206d17151f.png align="center")

Step 7 : Verify the running service by executing:

```bash
docker service ls
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690519282388/74d8034e-d8dc-4407-a40b-85d5fa9ab351.png align="center")

step 8 : The service will create containers on the Manager node. Check them by running:

```bash
docker ps
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690519348172/263a886f-4543-433f-97b9-b776da57123b.png align="center")

Step 9 : Now you can observe the Docker container running on any instance.

url : &lt;PublicIP&gt;:8000

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690519500705/f9258b32-baa2-49b1-b8a6-28a0fc35d032.png align="center")

Step 10 : If you wish to remove any node, execute the following command from the worker node.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690519711957/07763ed2-6f44-48e3-bd0d-d8f418b8427f.png align="center")

By running `docker node ls`, you can check the node list.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690519831129/ebd4efe8-88b6-4724-85d4-eb2db83784b9.png align="center")

That's all for this project! Embrace the power of Docker Swarm to take your web application deployment to the next level. #DockerSwarm #Containerization #Scalability #HighAvailability #DevOps #WebAppDeployment #AWS #CloudComputing #Automation
