Building a Three-Tier Application with Docker

by Shruti Mishra, 21BCP110

In this blog, we'll create a simple three-tier application using Docker. The application will consist of a html web server (Nginx), a backend server (Node.js), and a database server (MySQL). We'll use Docker to containerize each component, ensuring that our application is portable and easy to deploy.

Prerequisites:


(1) Creating the Three-Tier App:

Step 1: Create Frontend Tier

This tier is in charge of displaying information to the user and managing user interactions. It encompasses various user interfaces such as web browsers, mobile apps, or desktop applications.

My Frontend Tier consists:

Step 1: Lorem Ipsum

Step 2: Create Backend Tier

This tier encapsulates the core functionality of the application, including processing user requests, executing calculations, and communicating with the data storage layer. It may involve application servers, APIs, and microservices.

I have created the Backend using Node.js.

Step 1: Lorem Ipsum

Step 3: Create Database Tier

This tier is responsible for storing and organizing the data that the application uses. It can utilize a relational database, NoSQL database, file system, or any other data storage mechanism.

I have used MySQL for my Database Management System.

Step 1: Lorem Ipsum

(2) Creating the Dockerfiles for Three-Tier App:

Step 1: Create Dockerfile for Frontend

frontend-nginx -> Dockerfile:

Step 1: Lorem Ipsum

frontend -> nginx-conf:

Step 1: Lorem Ipsum

Step 2: Create Dockerfile for Backend

Dockerfile:

Step 1: Lorem Ipsum

Step 3: Create Dockerfile for MySQL Database

Dockerfile:

Step 1: Lorem Ipsum

(3) Creating the Docker Compose File:

Create Docker-Compose for the Application

docker-compose.yml:

Step 1: Lorem Ipsum

(4) Building and Running the Application:

Run the following command in the terminal:


    docker-compose up --build
        
Step 1: Lorem Ipsum Step 1: Lorem Ipsum

(5) Application is Successfully Built:


    docker ps
        
Step 1: Lorem Ipsum

Docker Desktop:

Step 1: Lorem Ipsum

(6) View Running Application:

1. Frontend:

Step 1: Lorem Ipsum

2. Backend:

Step 1: Lorem Ipsum

(7) Manupulating MySQL Database via Docker:

Run the following command in terminal:


    docker exec -t container_id mysql -u name_of_user -p
        
Step 1: Lorem Ipsum

Manupulate the database:

Step 1: Lorem Ipsum

(8) Push the Docker Images on Docker-Hub:

Run the following commands in terminal:


    docker tag SOURCE_IMAGE TARGET_IMAGE[:TAG]
        

    docker push TARGET_IMAGE[:TAG]
        

Step 1: Tag and Push Frontend Image

Tag and Push:

Step 1: Lorem Ipsum

Image:

Step 1: Lorem Ipsum

View Image on Docker-Hub:

Frontend-Image-URL

Step 2: Tag and Push Backend Image

Tag and Push:

Step 1: Lorem Ipsum

Image:

Step 1: Lorem Ipsum

View Image on Docker-Hub:

Backend-Image-URL

Step 3: Tag and Push Database Image

Tag and Push:

Step 1: Lorem Ipsum

Image:

Step 1: Lorem Ipsum

View Image on Docker-Hub:

Database-Image-URL