Deploy a 3-Tier Dockerized Application on AWS EC2
Deploy a simple 3-tier application on AWS EC2 using Docker. This project demonstrates deploying a React frontend, Node.js backend, and MySQL database while configuring AWS Security Groups for secure communication between the application layers.
Architecture
1
2
3
4
5
6
7
8
9
10
11
12
13
Internet
|
v
Frontend EC2
React + Nginx + Docker
|
v
Backend EC2
Node.js + Express + Docker
|
v
Database EC2
MySQL + DockerTechnologies
- AWS EC2
- Docker
- React.js
- Node.js
- Express.js
- MySQL
- Nginx
- Ubuntu
Deployment Steps
1. Create EC2 Instances
Create three Ubuntu EC2 instances:
- Frontend
- Backend
- Database
Configure Security Groups to allow only the required ports.
2. Install Docker
1
2
3
sudo apt update
sudo apt install docker.io -y
sudo systemctl enable --now docker3. Deploy Backend
1
2
3
4
5
git clone <your-repository>
cd backend
docker build -t backend .
docker run -d --name backend -p 5000:5000 backend4. Deploy Database
1
2
3
4
5
6
7
8
docker volume create mysql-data
docker run -d \
--name mysql \
-e MYSQL_ROOT_PASSWORD=mysecretpassword \
-e MYSQL_DATABASE=myapp \
-v mysql-data:/var/lib/mysql \
mysql:95. Deploy Frontend
1
2
3
4
5
6
docker build -t frontend .
docker run -d \
--name frontend \
-p 80:80 \
frontendAccess the application:
1
http://<FRONTEND_PUBLIC_IP>Security
The database should not be publicly accessible.
1
2
3
4
5
6
7
Internet
↓
Frontend
↓
Backend
↓
DatabaseAllow database traffic only from the backend Security Group.
Production Improvements
For production, consider using:
- Amazon RDS
- Amazon ECR
- Application Load Balancer
- Private Subnets
- AWS Secrets Manager
- CloudWatch
- Jenkins or GitHub Actions
Conclusion
This project provides hands-on experience with AWS EC2, Docker, application networking, Security Groups, and 3-tier architecture and can be extended into a complete CI/CD DevOps project.
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article