DEV Community

Cover image for ๐Ÿš€Deployed a Containerized Flask Message App on AWS EC2 using Docker
Avinash wagh
Avinash wagh

Posted on

๐Ÿš€Deployed a Containerized Flask Message App on AWS EC2 using Docker

In this article, Iโ€™ll walk through how I built and deployed a containerized Message Board Web Application using Python Flask and MySQL on AWS EC2. This project helped me gain hands-on experience with Docker, cloud deployment, and backend development.


๐Ÿ“Œ Project Overview

The application is a simple message board where users can:

  • Add messages
  • Delete messages
  • Store data in a MySQL database

Both the application and database are containerized using Docker and communicate over a shared network.


๐Ÿ› ๏ธ Tech Stack

  • Python
  • Flask
  • MySQL
  • Docker
  • AWS EC2
  • Linux

๐Ÿ—๏ธ Architecture

The project consists of two main containers:

  • Flask Application Container
  • MySQL Database Container

These containers are connected via a custom Docker network:

message-network
Enter fullscreen mode Exit fullscreen mode

The Flask app connects to MySQL using the container name (mysql-db) as the hostname.


โš™๏ธ Step-by-Step Implementation

1๏ธโƒฃ Create Docker Network

docker network create message-network
Enter fullscreen mode Exit fullscreen mode

2๏ธโƒฃ Run MySQL Container

docker run -d \
--name mysql-db \
--network message-network \
-e MYSQL_ROOT_PASSWORD=root \
-e MYSQL_DATABASE=messagedb \
mysql:8
Enter fullscreen mode Exit fullscreen mode

3๏ธโƒฃ Build Flask App Image

docker build -t flask-message-app .
Enter fullscreen mode Exit fullscreen mode

4๏ธโƒฃ Run Flask Container

docker run -d \
-p 5001:5001 \
--network message-network \
--name flask-app \
flask-message-app
Enter fullscreen mode Exit fullscreen mode

๐ŸŒ Deployment on AWS EC2

I deployed this project on an AWS EC2 instance by:

  • Launching a Linux-based EC2 instance
  • Installing Docker
  • Running both containers inside the instance
  • Configuring the Security Group to allow inbound traffic on port 5001

๐Ÿ”— Live Demo

๐ŸŒ http://13.235.243.101:5001


๐Ÿ“ท Screenshots

  • Web Application UI

  • Mobile View

  • Running Docker Containers

  • MySQL Database Table


๐Ÿ“š Key Learnings

  • Understanding Docker containerization
  • Managing multi-container applications
  • Setting up Docker networks for communication
  • Deploying applications on AWS EC2
  • Troubleshooting real-world issues

๐Ÿš€ Future Improvements

  • Add message timestamps
  • Implement edit functionality
  • Use Docker Compose
  • Add Nginx reverse proxy
  • Set up CI/CD pipeline

๐Ÿ”— GitHub Repository

๐Ÿ‘‰ https://github.com/Avinash8600/containerized-flask-message-app


๐Ÿ‘จโ€๐Ÿ’ป About Me

Iโ€™m a Software Engineer with a focus on Cloud and DevOps, passionate about building and deploying scalable applications.


๐Ÿ’ฌ Conclusion

This project was a great hands-on experience in combining backend development with cloud and containerization technologies. It helped me understand how real-world applications are deployed and managed.

If you have any feedback or suggestions, feel free to share!


Top comments (2)

Collapse
ย 
alok38 profile image
alok-38 โ€ข

Excellent write up. So easy to follow.

Collapse
ย 
avinashwagh profile image
Avinash wagh โ€ข

Really appreciate your feedback! ๐Ÿ™Œ
My goal is to break down complex topics like Docker, Cloud, and DevOps into simple, easy-to-understand concepts. Glad it helped!