Update README.md

This commit is contained in:
Puneet Khurana 2025-03-26 10:17:20 +00:00
parent dc05d73cdd
commit d57cb7143a

129
README.md
View File

@ -1,47 +1,136 @@
Last login: Mon Mar 17 20:02:32 on ttys001
\# Web Application Docker Deployment Documentation
Conditions for Deploying and Running the Application
To deploy and run this web application, the following software must be installed on your system:
The default interactive shell is now zsh.
To update your account to use zsh, please run `chsh -s /bin/zsh`.
For more details, please visit https://support.apple.com/kb/HT208050.
MacBookPro:~ puneetkhurana$ cd Documents/
MacBookPro:Documents puneetkhurana$ cd zkt25/
MacBookPro:zkt25 puneetkhurana$ cd z1/
MacBookPro:z1 puneetkhurana$ vim README.md
# Docker
Install Docker (with Docker Compose) to create and manage containers.
# Git
Ensure Git is installed if you're cloning the project repository.
# A terminal/command-line interface
You will need a terminal for executing shell scripts and commands.
# A web browser
Used to access the web application once it is deployed (recommended: Google Chrome or Mozilla Firefox).
# Description of the Application
This application is a basic PHP web application connected to a MySQL database. It consists of the following components:
Apache Web Server with PHP: The Apache service runs the PHP application and serves it through the web server.
MySQL Database: A MySQL database that stores user data and other application-related information.
Persistence Mechanism: Uses Docker volumes to ensure that data stored in the MySQL database persists even after the containers are stopped or removed.
Virtual Networks and Named Volumes Used by the Application
Network:
The containers are connected via a custom Docker bridge network named my_network. This allows communication between the Apache-PHP service and the MySQL service.
# Named Volume:
mysql_data: A named volume used to store the database data persistently. This ensures that even if the containers are removed or recreated, the database data will be preserved.
# Container Configuration
The application consists of the following Docker containers:
1. Apache-PHP Container
Service Name: apache
Image: Official php:apache image.
Ports:
Exposes port 8080 for accessing the web application through a browser.
Volume Mapping:
Maps the app directory from the host machine to the container, where the PHP files are stored and served.
2. MySQL Container
Service Name: mysql
Image: Official mysql image.
Ports:
Exposes port 3306 for database communication (typically used for internal communication with the Apache-PHP container).
# Volume Mapping:
Uses a named volume mysql_data for persisting database data.
# Containers Used and Brief Description
apache:
This container runs the Apache web server with PHP support. It serves the PHP files that are located in the app directory.
mysql:
This container runs the MySQL database. It stores and manages the data for the PHP application, using the mysql_data volume for persistence.
Instructions on How to Prepare, Run, Pause, and Delete the Application
1. Prepare the Application
To set up the necessary network and volume, run the following command:
Start the Application**
This script **starts all services in the background**:
bash
Copy
Edit
./prepare-app.sh
This script will:
Create the custom Docker network (my_network).
Create the named volume (mysql_data).
Set up the application directory and create a test PHP file.
2. Start the Application
To start the application and run the containers in detached mode, execute:
bash
Copy
Edit
./start-app.sh
This script will:
Expected output:
Start the Docker containers (apache and mysql).
Starting application...
Application started. Access it at http://localhost:8080
Wait for a few seconds to ensure all services are up and running.
Display a message with the URL to access the web application.
view the Application in a Web Browser**
- Open **[http://localhost:8080](http://localhost:8080)**
- You should see: `Welcome to My Nginx Server!`
Pause the Application (Without Deleting Data)**
To stop the application while keeping data intact:
3. Pause the Application
To stop the running containers without deleting data, use:
bash
Copy
Edit
./stop-app.sh
This will:
Expected output:
Stop the containers (apache and mysql).
4. Delete the Application
To completely remove the containers, networks, and volumes, run:
bash
Copy
Edit
./remove-app.sh
This will:
# Remove the apache and mysql containers.
# Delete the custom Docker network and the named volume mysql_data.
# Instructions on How to View the Application on the Web
Once the application is running, open a web browser and navigate to:
plaintext
Copy
Edit
# http://localhost:8080/index.php
This page will test the connection to the MySQL database. If the connection is successful, a confirmation message will be displayed.
# Conclusion
This project demonstrates how to deploy a simple PHP application with a MySQL database using Docker. By using Docker Compose, the application ensures modularity and ease of deployment, while the named volume ensures that database data is persisted across container restarts.