In this practice we will be creating 3-Tier project to containerize the same using docker-compose.
Let's start then,
Prerequisite
=> Docker Must be installed
=> A Good internet connection
=> Docker Compose should be installed
=> Visual Studio Code should be installed
About Three-Tier project
Three-tier architecture is a software application architecture that organizes applications into three logical and physical computing tiers:
the presentation tier, the application tier and the data tier.
The presentation tier is the user interface layer, where the user interacts with the application.
The application tier is the logic layer, where data is processed using business rules.
The data tier is the database layer, where data is stored and managed.
The main benefit of three-tier architecture is that each tier can be developed, updated and scaled independently, without affecting the other tiers. It also provides better maintainability, flexibility and reusability of code.
=> Application Tier will use ubuntu and PHP.
=> Presentation Tier will use Apache.
version: "3"services:frontend:image: httpd:latestvolumes:- "./frontend:/usr/local/apache2/htdocs"ports:- 3000:80backend:container_name: simple-backendbuild:context: ./dockerfile: Dockerfilevolumes:- "./api:/var/www/html/"ports:- 5000:80database:image: mysql:latestenvironment:MYSQL_DATABASE: todo_appMYSQL_USER: todo_adminMYSQL_PASSWORD: passwordMYSQL_ALLOW_EMPTY_PASSWORD: 1volumes:- "./db:/docker-entrypoint-initdb.d"phpmyadmin:image: phpmyadmin/phpmyadminports:- 8080:80environment:- PMA_HOST=database- PMA_PORT=3306depends_on:- database
Let we run the project as below and see the results.
PS D:\Docker> docker compose up [+] Building 0.0s (0/0) [+] Running 4/0 ✔ Container docker-database-1 Created 0.0s ✔ Container docker-phpmyadmin-1 Created 0.0s ✔ Container docker-frontend-1 Created 0.0s ✔ Container simple-backend Created 0.0s Attaching to docker-database-1, docker-frontend-1, docker-phpmyadmin-1, simple-backend docker-database-1 | 2023-07-26 12:03:46+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.34-1.el8 started. docker-frontend-1 | AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.20.0.4. Set the 'ServerName' directive globally to suppress this message docker-frontend-1 | AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.20.0.4. Set the 'ServerName' directive globally to suppress this message
Now Open browser and below URL.
http://localhost:3000/
So we can see we are able to fetch data directly from DB, Hence this practice completes now.
.png)
No comments:
Post a Comment