AWS Builder Center

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 + Docker

Technologies

  • 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 docker

3. 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 backend

4. 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:9

5. Deploy Frontend

1
2
3
4
5
6
docker build -t frontend .

docker run -d \
--name frontend \
-p 80:80 \
frontend
Access 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
↓
Database
Allow 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.
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article