When I started learning Docker, I had no idea I’d end up deploying a real application on a cloud server within the same month.
It ended up changing how I think about building software.
The Idea
I didn’t want to build just another static project.
I wanted:
- A real backend
- A real database
- A real deployment
So I built a simple web app that tracks page visits and stores them in PostgreSQL.
Tech Stack
- Python Flask (backend)
- PostgreSQL (database)
- Docker & Docker Compose
- AWS EC2 (deployment)
Architecture
User (Internet)
↓
AWS EC2 Server
↓
Docker Engine
↓
Flask Container (Port 80)
↓ psycopg2
PostgreSQL Container
↓
Persistent Volume (pgdata)
Key Concepts I Implemented
🔹 Multi-container system
Instead of running containers manually, I used Docker Compose.
docker compose up -d
This starts the entire system in one command.
🔹 Environment variables (.env)
No secrets inside the code.
- Cleaner
- Safer
- Production-ready
🔹 Health checks
Docker monitors the application continuously.
If Flask stops responding, the container is marked as unhealthy.
🔹 Auto-restart
Using:
restart: always
If a container crashes, Docker automatically restarts it.
🔹 Optimized Dockerfile
- Used
python:3.10-slim - Cleared apt cache after install
- Used
--no-cache-dirfor pip - Optimized layer ordering
Result: Image size reduced significantly (~300MB → ~160MB)
Biggest Challenge
Connecting Flask to PostgreSQL inside Docker.
The key realization:
Containers communicate using service names, not IP addresses.
DB_HOST=db
Docker internally resolves db to the PostgreSQL container.
Once this clicked, the setup became much clearer.
Deployment
I deployed the app on AWS EC2.
Steps:
- Launch EC2 instance
- Install Docker
- Clone project
- Run Docker Compose
The application was then accessible via a public IP.
What I Learned
Docker is not just about containers.
It’s about building systems that are:
- Reproducible
- Isolated
- Self-healing
- Easy to deploy
Links
- GitHub: https://github.com/tj2905/flask-docker-app
- Docker Hub: https://hub.docker.com/r/tanayjain29/flask-devops-app
Final Thoughts
This project was my first real experience combining backend, database, and deployment into one system.
If you're learning Docker, building and deploying even a small project like this gives much more clarity than just following tutorials.
Top comments (1)
Built this while learning Docker — would love feedback or suggestions to improve 🙌