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.

0
Subscribe to my newsletter

Read articles from BHASHWANTH PALUKURI directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

BHASHWANTH PALUKURI
BHASHWANTH PALUKURI