Building and Deploying a 3-Tier Application Using Docker & Docker Compose

๐ Deploying a 3-Tier Application Using Docker and Docker Compose
Author: Palukuri Bhashwanth
Date: May 2025
Project: Bhashwanth-application (App Layer), bhashwanth-database (DB Layer)
๐ Introduction
In this blog, Iโll walk you through how I containerized and deployed a 3-tier application using Docker and Docker Compose. The application consists of:
Frontend/Backend (App Layer):
Bhashwanth-application
Database Layer:
bhashwanth-database
Reverse Proxy (Load Balancer): Nginx
๐งฑ Architecture Overview
pgsqlCopyEdit +---------------------+
| NGINX Proxy | (Load Balancer)
+---------------------+
|
-------------------------
| |
+-------------------+ +----------------------+
| Bhashwanth-application | | bhashwanth-database |
+-------------------+ +----------------------+
(App) (MySQL/Postgres)
โ๏ธ Technologies Used
Docker
Docker Compose
NGINX (as reverse proxy)
Python/Node.js for application (depending on use case)
MySQL/PostgreSQL for the database
๐ Project Structure
pgsqlCopyEditdockerwebapp/
โ
โโโ bhashwanth-application/
โ โโโ app.py / index.js
โ โโโ requirements.txt / package.json
โ โโโ Dockerfile
โ
โโโ bhashwanth-database/
โ โโโ init.sql
โ
โโโ nginx/
โ โโโ default.conf
โ
โโโ docker-compose.yml
๐ณ Dockerfile (for Bhashwanth-application)
Example for a Python Flask app:
DockerfileCopyEditFROM python:3.9-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
CMD ["python", "app.py"]
๐ฌ Docker Compose File: docker-compose.yml
yamlCopyEditversion: '3.8'
services:
app:
build: ./bhashwanth-application
container_name: bhashwanth-app
ports:
- "5000:5000"
depends_on:
- db
db:
image: mysql:8.0
container_name: bhashwanth-database
environment:
MYSQL_ROOT_PASSWORD: rootpass
MYSQL_DATABASE: bhashwanthdb
MYSQL_USER: bhashwanth
MYSQL_PASSWORD: bhash123
volumes:
- db_data:/var/lib/mysql
nginx:
image: nginx:latest
container_name: bhashwanth-nginx
ports:
- "80:80"
volumes:
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf
depends_on:
- app
volumes:
db_data:
๐งช Running the Application
In your project root (dockerwebapp
), simply run:
bashCopyEditdocker-compose up --build
To run in detached mode:
bashCopyEditdocker-compose up -d
Access the app via:
arduinoCopyEdithttp://localhost/
โ What I Learned
How to set up a multi-container app using Docker Compose
How to define service dependencies
How to expose ports and use environment variables
How to simulate production using NGINX reverse proxy
๐ Future Enhancements
Add CI/CD pipeline using GitHub Actions or Jenkins
Add logging and monitoring (ELK Stack / Prometheus + Grafana)
Deploy to cloud platforms (AWS ECS, Azure App Service, etc.)
๐ Conclusion
Containerizing and orchestrating a 3-tier application with Docker Compose makes development and deployment easier and more consistent. This hands-on project helped me grasp the end-to-end DevOps process using containers.
Subscribe to my newsletter
Read articles from BHASHWANTH PALUKURI directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
