Two-tier Web Application Deployment using Docker Compose
Table of contents
- Introduction to Docker Compose ๐ข
- Docker Compose Essentials ๐ณ
- What is Two-tier Architecture?
- Step 1: Set Up Your Environment ๐๏ธ
- Step 2: Clone the Code ๐
- Step 3: Install Docker Compose
- Step 4: Deploy the Application ๐
- Step 5: Verify Containers
- Step 6: Explore the Docker Compose File ๐
- Step 7: Access MySQL Database
- Step 8: Create the database and table
- Step 9: Access the Application ๐
- Step 10: Test Data Persistence
- Congratulations, you've successfully created and enhanced a Two-Tier Project using Docker Compose.
Introduction to Docker Compose ๐ข
Docker Compose is a tool that was developed to help define and share multi-container applications. With Compose, we can create a YAML file to define the services and with a single command, can spin everything up or tear it all down.
Docker Compose Essentials ๐ณ
Docker Compose empowers you with a set of essential features to manage your containerized applications efficiently
YAML Configuration ๐
Docker Compose uses a YAML file, usually named docker-compose.yml
, to define your application's services, networks, and volumes. This human-readable configuration provides a clear overview of your application's structure.
What is Two-tier Architecture?
Two-tier architecture, also known as two-layer architecture, is a software architecture design in which an application is divided into two distinct layers or tiers:
Presentation Layer (Client Tier):
This is the user interface or the front-end layer of the application that interacts directly with users.
It is responsible for presenting data and user interfaces to the users, typically through a graphical user interface (GUI).
User interactions, such as input validation and user interface logic, are managed in this layer.
The presentation layer communicates with the data layer to retrieve or store data.
Data/Storage Layer (Server Tier):
This is the back-end layer that handles data storage, retrieval, and manipulation.
It is responsible for managing data storage, databases, and data-related operations.
Business logic and application functionality that involve data processing are typically handled in this layer.
The data layer communicates with the presentation layer to provide the requested data or to store data submitted by users.
Step 1: Set Up Your Environment ๐๏ธ
Launch an EC2 instance on AWS and SSH into it. If you need help with launching
create a new directory.
mkdir two-tier-app cd two-tier-app
Step 2: Clone the Code ๐
Clone the code from GitHub and navigate into the cloned directory:
https://github.com/kajalDevOps/two-tier-flask-app.git
Step 3: Install Docker Compose
sudo apt install docker-compose -y
Step 4: Deploy the Application ๐
Start the application using Docker Compose in detached mode:
docker-compose up
Step 5: Verify Containers
docker ps
Step 6: Explore the Docker Compose File ๐
Let's take a closer look at our docker-compose.yaml
file:
Step 7: Access MySQL Database
docker exec -it <CONTAINER_ID> bash
mysql -u root -p
Step 8: Create the database and table
use two_tier;
show databases;
select * from messages;
show table;
Step 9: Access the Application ๐
Open port 5000 in your EC2 instance's Security Group inbound rules.
Access the Two-Tier App from your EC2 instance's public IP address:
Step 10: Test Data Persistence
Test data persistence by shutting down the containers:
docker-compose down
Restart the application using Docker Compose
docker-compose up -d
Congratulations, you've successfully created and enhanced a Two-Tier Project using Docker Compose.
Subscribe to my newsletter
Read articles from Girdhar Kajal directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by