My DevOps Project: Building a Two-Tier Flask App with MySQL
After a long journey in DevOps, I’m excited to share my latest project! I’ll be using a GitHub repository to build a two-tier Flask application connected to a MySQL database. Here’s a step-by-step guide on how I set it up.

Project Overview:
In this project, I create a Flask app that takes input from environment variables and stores it in a MySQL database.
GitHub Repository:
Two-Tier Flask App
Step-by-Step Instructions
1. Clone the Repository
git clone https://github.com/LondheShubham153/two-tier-flask-app2. Build the Docker Image
Navigate to the cloned directory and build the Docker image:
docker build -t two-tier-app:latest .3. Create a Custom Network
List the existing Docker networks:
docker network lsCreate a custom network named twotier:
docker network create twotier4. Set Up MySQL
a. Create a Docker Volume:
docker volume ls
docker volume create mysql-datab. Run the MySQL Container:
docker run -d --name mysql-demo -v mysql-data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=root mysql:5.7c. Access the MySQL Container:
docker exec -it mysql-demo bashd. Log in to MySQL and Create a Database:
mysql -u root -p
# Enter the password: root
CREATE DATABASE devops;
exit
exite. Run MySQL with the Custom Network:
docker run -d -v mysql-data:/var/lib/mysql --network twotier --name mysql -e MYSQL_DATABASE=devops -e MYSQL_ROOT_PASSWORD=root mysql:5.7Explanation:
-v mysql-data:/var/lib/mysql: Binds themysql-datavolume to the container's MySQL data directory.--network twotier: Connects the container to thetwotiernetwork.--name mysql: Names the containermysql.-e MYSQL_DATABASE=devops -e MYSQL_ROOT_PASSWORD=root: Sets the database name and root password using environment variables.
5. Run the Flask App
Run the Flask Container:
docker run -d --network twotier --name two-tier-app -e MYSQL_HOST=mysql -e MYSQL_USER=root -e MYSQL_PASSWORD=root -e MYSQL_DB=devops -p 5000:5000 two-tier-app:latestExplanation:
--network twotier: Connects the Flask container to thetwotiernetwork.- Environment variables (
MYSQL_HOST,MYSQL_USER,MYSQL_PASSWORD,MYSQL_DB) pass necessary information for the Flask app to connect to the MySQL database. -p 5000:5000: Exposes port 5000 to access the Flask app.
Here is the YouTube Link: https://youtube.com/@raeesq.?si=v_QK6Q2XXMf9mKep
Conclusion
This project demonstrates how to create a two-tier architecture using Docker, connecting a Flask app with a MySQL database. I hope you find this project helpful and inspiring for your own DevOps journey!
Comments
Post a Comment