Deploy a two tier application using docker

priyanka kumari
3 min readNov 23, 2023

--

πŸš€ Thrilled to share the success of a hands-on Docker project! πŸ³πŸ’» Recently, I wrapped up a hands-on experience deploying a two-tier Flask application paired with MySQL. The journey involved delving into the complexities of containerized architecture, with a special emphasis on establishing seamless communication between the front-end Flask app and the back-end MySQL database. πŸ›³οΈβœ¨

Quick Steps:

  1. Cloned a Git repo on AWS EC2.

2. Created a MySQL volume for persistent data.

mkdir volumes
cd volumes
mkdir flask-app
cd two-tier-flask-app/
docker volume create β€” name mysql-volume β€” opt type=none β€” opt device=/home/ubuntu/mydockerbuild/volumes β€” opt o=bind

3. Launched MySQL container with proper configuration.

4. Checked the database and confirmed volume mount.

docker ps
docker exec -it <container id> bash
mysql -u root -p
show databases;

5. Built and ran the Flask app container, facing and resolving container isolation issues.

docker build -t flask-app .
docker images
docker run -d -p 5000:5000 β€” name flask-app -e MYSQL_HOST=mysql -e MYSQL_USER=admin -e MYSQL_PASSWORD=<youradminpassword> -e MYSQL_DB=testdb flask-app:latest

6. Created a Docker network for communication.

7. Added both MySQL and Flask containers to the network.

docker kill <container id> docker rm <container id> docker run -d -p 3306:3306 β€” mount source=mysql-volume,target=/var/lib/mysql β€” name mysql β€” network two-tier-app-nw -e MYSQL_ROOT_PASSWORD=<your password> -e MYSQL_DATABASE=testdb -e MYSQL_USER=admin -e MYSQL_PASSWORD=<yourpassword> mysql:latest docker inspect <network name> docker run -d -p 5000:5000 β€” name flask-app β€” network two-tier-app-nw -e MYSQL_HOST=mysql -e MYSQL_USER=admin -e MYSQL_PASSWORD=<yourpassword> -e MYSQL_DB=testdb flask-app:latest docker inspect <network name>

Congratulations! The app is up and running.

Achieved a fully functional two-tier architecture, enhancing understanding of Docker orchestration. Explore the deployed app at EC2 IP:5000 and confirmed successful data interaction with MySQL. πŸŽ‰πŸπŸ“¦

Feel free to share

I hope this is useful for you?

βœ…Reshare this with others so that it helps more people

βœ…Tag your colleagues and friends who you think will need this

--

--

priyanka kumari
priyanka kumari

Written by priyanka kumari

Cloud || Devops enthusiast|| Learning & helping

No responses yet