2.6 KiB
Docker Web Application
Overview
This is a Dockerized web application consisting of two services:
- 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.
The web service demonstrates basic functionality and includes an endpoint (/dbtest
) to test connectivity with the database service.
Deployment Requirements
- Docker: Ensure Docker is installed and running.
- Docker Compose: Version 3.8 or later is required to run the multi-container application.
Application Architecture
-
Virtual Network:
A custom Docker networkapp-network
is used to allow seamless communication between containers. -
Named Volume:
A persistent volumedb_data
is defined to store MySQL database data, ensuring data persistence between container restarts.
Container Configurations
-
Web Service Container:
- Image: Custom built from the provided
Dockerfile
. - Port: Exposes port
5000
. - Environment Variables: Set for database connectivity (e.g.,
MYSQL_HOST
,MYSQL_USER
,MYSQL_PASSWORD
,MYSQL_DATABASE
). - Restart Policy: Configured to always restart on failure.
- Image: Custom built from the provided
-
Database Service Container:
- Image: Official
mysql:8.0
image. - Ports: Exposes port
3306
. - Environment Variables: Defines
MYSQL_ROOT_PASSWORD
andMYSQL_DATABASE
for initial configuration. - Volume: Uses named volume
db_data
for data persistence. - Restart Policy: Configured to always restart on failure.
- Image: Official
Used Containers
- web: The Flask-based web server.
- db: The MySQL database server.
How to Use the Application
-
Prepare the Application:
Run the following command to build images and create required networks/volumes:./prepare-app.sh
-
Start the Application: Launch the containers with:
./start-app.sh You should see a message: Running app ... The app is available at http://localhost:5000
-
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. • Visit http://localhost:5000/dbtest to test the database connectivity.
-
Stop the Application: To stop all running services without removing their state:
./stop-app.sh
-
Remove the Application: When you want to completely remove all containers, networks, and volumes:
./remove-app.sh