This project demonstrates how to set up a two-tier application using Docker containers:
- A Flask-based frontend running a simple web app
- A MySQL database backend
Connected via a user-defined Docker bridge network to enable inter-container communication.
- Launching an EC2 instance and SSH connection using a
.pem
file - Installing Docker on Ubuntu (WSL or EC2)
- Cloning this repository
- Building a custom Docker image for the Flask app
- Creating a user-defined Docker network
- Running MySQL and Flask app containers on the same network
- Testing the application via browser and MySQL shell
- AWS EC2 instance (Ubuntu preferred)
- Docker installed
- Git installed
- SSH access with PEM file
docker build -t two-tier-app .
docker network create two-tier -d bridge
docker run -d --name mysql --network two-tier \
-e MYSQL_ROOT_PASSWORD=root \
-e MYSQL_DATABASE=devops \
mysql
docker run -d -p 5000:5000 --network two-tier \
-e MYSQL_HOST=mysql \
-e MYSQL_USER=root \
-e MYSQL_PASSWORD=root \
-e MYSQL_DB=devops \
two-tier-app:latest
Once both containers are running, open your browser and go to:
http://<your-ec2-public-ip>:5000
Make sure port 5000 is open in your EC2 security group.
docker exec -it <mysql_container_id> bash
mysql -u root -p
SHOW DATABASES;
USE devops;
SELECT * FROM messages;
Watch Tutorial on YouTube