Update z1/README.md

This commit is contained in:
Danylo Kunak 2025-03-17 23:31:41 +00:00
parent 71cc75c7a0
commit 046f0bfe67

View File

@ -1,65 +1,68 @@
# Docker Web Application # Docker Web Application
## Overview ## Overview
This is a Dockerized web application consisting of two services: This is a Dockerized web application consisting of two services:
- **Web Service:** A simple Python Flask application serving HTTP endpoints. - **Web Service:** A simple Python Flask application serving HTTP endpoints.
- **Database Service:** A MySQL 8.0 database that stores its data in a persistent volume. - **Database Service:** A MySQL 8.0 database that stores its data in a persistent volume.
The web service demonstrates basic functionality and includes an endpoint (`/dbtest`) to test connectivity with the database service. The web service demonstrates basic functionality and includes an endpoint (`/dbtest`) to test connectivity with the database service.
## Deployment Requirements ## Deployment Requirements
- **Docker:** Ensure Docker is installed and running. - **Docker:** Ensure Docker is installed and running.
- **Docker Compose:** Version 3.8 or later is required to run the multi-container application. - **Docker Compose:** Version 3.8 or later is required to run the multi-container application.
## Application Architecture ## Application Architecture
- **Virtual Network:** - **Virtual Network:**
A custom Docker network `app-network` is used to allow seamless communication between containers. A custom Docker network `app-network` is used to allow seamless communication between containers.
- **Named Volume:** - **Named Volume:**
A persistent volume `db_data` is defined to store MySQL database data, ensuring data persistence between container restarts. A persistent volume `db_data` is defined to store MySQL database data, ensuring data persistence between container restarts.
## Container Configurations ## Container Configurations
- **Web Service Container:** - **Web Service Container:**
- **Image:** Custom built from the provided `Dockerfile`. - **Image:** Custom built from the provided `Dockerfile`.
- **Port:** Exposes port `5000`. - **Port:** Exposes port `5000`.
- **Environment Variables:** Set for database connectivity (e.g., `MYSQL_HOST`, `MYSQL_USER`, `MYSQL_PASSWORD`, `MYSQL_DATABASE`). - **Environment Variables:** Set for database connectivity (e.g., `MYSQL_HOST`, `MYSQL_USER`, `MYSQL_PASSWORD`, `MYSQL_DATABASE`).
- **Restart Policy:** Configured to always restart on failure. - **Restart Policy:** Configured to always restart on failure.
- **Database Service Container:** - **Database Service Container:**
- **Image:** Official `mysql:8.0` image. - **Image:** Official `mysql:8.0` image.
- **Ports:** Exposes port `3306`. - **Ports:** Exposes port `3306`.
- **Environment Variables:** Defines `MYSQL_ROOT_PASSWORD` and `MYSQL_DATABASE` for initial configuration. - **Environment Variables:** Defines `MYSQL_ROOT_PASSWORD` and `MYSQL_DATABASE` for initial configuration.
- **Volume:** Uses named volume `db_data` for data persistence. - **Volume:** Uses named volume `db_data` for data persistence.
- **Restart Policy:** Configured to always restart on failure. - **Restart Policy:** Configured to always restart on failure.
## Used Containers ## Used Containers
- **web:** The Flask-based web server. - **web:** The Flask-based web server.
- **db:** The MySQL database server. - **db:** The MySQL database server.
## How to Use the Application ## How to Use the Application
1. **Prepare the Application:** 1. **Prepare the Application:**
Run the following command to build images and create required networks/volumes: Run the following command to build images and create required networks/volumes:
```bash ```bash
./prepare-app.sh ./prepare-app.sh
2. **Start the Application:** 2. **Start the Application:**
Launch the containers with: Launch the containers with:
./start-app.sh ```bash
You should see a message: ./start-app.sh
Running app ... You should see a message:
The app is available at http://localhost:5000 Running app ...
The app is available at http://localhost:5000
3. **Interact with the Application:**
3. **Interact with the Application:**
• Open your web browser and go to http://localhost:5000 to view the home page.
• Visit http://localhost:5000/status for the application status. • Open your web browser and go to http://localhost:5000 to view the home page.
• Visit http://localhost:5000/dbtest to test the database connectivity. • Visit http://localhost:5000/status for the application status.
• Visit http://localhost:5000/dbtest to test the database connectivity.
4. **Stop the Application:**
To stop all running services without removing their state: 4. **Stop the Application:**
./stop-app.sh To stop all running services without removing their state:
```bash
5. **Remove the Application:** ./stop-app.sh
When you want to completely remove all containers, networks, and volumes:
./remove-app.sh 5. **Remove the Application:**
When you want to completely remove all containers, networks, and volumes:
```bash
./remove-app.sh