"Two-Tier Web App with Docker: Flask Frontend + MySQL Backend"

Search for a command to run...

No comments yet. Be the first to comment.
In this series, I will walk you through building a complete DevOps Mega Project using tools like Git, Docker, Jenkins, AWS, Kubernetes, and Terraform β from development to production deployment.
Hello DevOps enthusiasts! πIn this project, we'll walk through the deployment of a fully functional Netflix Clone using modern DevOps practices. Our CI/CD pipeline will be built using Jenkins, which will automate the build, test, and deployment proc...
Master GitLab CI/CD Variables, Secrets Management, Artifacts & Best Practices π Introduction In the previous article, we learned how GitLab Runners execute CI/CD pipelines and how to configure Self-H

Learn GitLab Runners, Hosted vs Self-Hosted Runners, Runner Registration, Tags, Pipeline Editor & Parallel Jobs π Introduction In the previous article, we created our first GitLab CI/CD pipeline and

Learn Continuous Integration, Continuous Delivery, Pipelines, Stages, Jobs & .gitlab-ci.yml π Introduction In the previous articles, we explored GitLab fundamentals, repository management, and collab

Learn Docker Scout, Multi-Stage Builds, Docker Hardened Images (DHI), SBOM, Docker Model Runner, Ask Gordon AI, and production-ready container security through practical, real-world examples. Introduc

Import Repositories, Mirroring & Repository Management Best Practices π Introduction In the previous articles, we learned the fundamentals of GitLab, created projects, and configured secure authentic

In this blog, Iβll walk you through how I deployed a two-tier Flask web application with a MySQL database using Docker containers on an AWS EC2 instance. This setup ensures container isolation, environment consistency, and real-time communication between the app and database via Docker networking.
By the end of this guide, your application will be accessible over the internet with just a public IP and a browser!
Go to AWS EC2 Console.
Launch a new instance with the following:
AMI: Ubuntu 20.04 or 22.04 LTS
Instance Type: t2.micro (Free Tier)
Storage: 8 GB or more
Security Group Rules:
SSH (Port 22) β for terminal access
HTTP (Port 80) β optional
Custom TCP (Port 5000) β to access Flask App
Key pair: Create or use an existing one (e.g., my-key.pem)
β Connect to the instance:
ssh -i my-key.pem ubuntu@your-public-ip

sudo apt update
sudo apt install -y docker.io
sudo usermod -aG docker $USER && newgrp docker
1. sudo apt update
Updates the package list to fetch the latest versions available from repositories.
2. sudo apt install -y docker.io
Installs Docker Engine from Ubuntuβs default repository without asking for confirmation.
3. sudo usermod -aG docker $USER && newgrp docker
Adds your user to the Docker group so you can run Docker without sudo.
clone https://github.com/ApurvGujjar07/Two-Tier-Flask-App-.git
cd two-tier-flask-app
ls
Youβll see files like app.py, Dockerfile, etc.
docker build -t two-tier-backend .
This command packages the app into a Docker image named two-tier-backend.

docker network create mynetwork
This allows containers to communicate internally by name (DNS-style linking).

docker run -d --name mysql --network mynetwork \
-e MYSQL_ROOT_PASSWORD=root \
-e MYSQL_DATABASE=devops \
mysql
β MySQL now runs and is ready for connection on the Docker network.

docker run -d -p 5000:5000 --network mynetwork \
-e MYSQL_HOST=mysql \
-e MYSQL_USER=root \
-e MYSQL_PASSWORD=root \
-e MYSQL_DB=devops \
two-tier-backend:latest
Your Flask app is now running and mapped to port 5000 of your EC2 instance.


Go to AWS Console β Security Groups
Add inbound rule:
Type: Custom TCP
Port: 5000
Source: Anywhere (0.0.0.0/0)
Then visit:
π http://<your-public-ip>:5000
β You should see the live Flask web app now!


docker exec -it mysql mysql -u root -p
# Enter: root
Then run:
SHOW DATABASES;
USE devops;
SHOW TABLES;
SELECT * FROM messages;


In this blog, I demonstrated how to:
Launch an EC2 instance
Install and configure Docker
Deploy a two-tier Flask + MySQL app
Connect containers via Docker network
Expose the app publicly via port 5000
This is a solid DevOps practice project showing real-world containerization, networking, and deployment skills.

Hi, I'm Apurv Gujjar, a passionate and aspiring DevOps Engineer.
"This project marks the beginning of my journey into the world of DevOps, containerization, and cloud-native application deployment."