| .. | ||
| backend | ||
| web | ||
| compose.yaml | ||
| minikube-linux-amd64 | ||
| prepare-app.sh | ||
| README.md | ||
| remove-app.sh | ||
| start-app.sh | ||
| stop-app.sh | ||
Visitor Counter Application
This project demonstrates a simple web application using Apache (web server), Flask (backend) and Redis(database), deployed with Docker Compose.
Prerequisites
- Docker Engine v20.10 or newer.
- Docker Compose v2.33.1 or newer.
Application Description
The application consists of two services:
- Web server (Apache) serving an HTML page.
- Backend (flask): Handles requests to '/counter'.
- Database (Redis) storing visitor counts persistently.
Instructions
-
Prepare the application: ./prepare-app.sh
-
Start the application: ./start-app.sh
-
Access the application at: http://localhost:5000 or run "hostname -I " and copy the ip address and Access the application at : http://[ip address you copied]:5000
-
Stop the application: ./stop-app.sh
-
Remove all resources: ./remove-app.sh
Virtual netwok and volumes
- A default network is created by docker compose for communication between these services
- A named volum ('redis_data') ensures Redis data persists across restarts.
Cross-Origin Resource Sharing (CORS)
Since the frontend (Apache) and backend (Flask) run on different ports, Cross-Origin Resource Sharing (CORS) has been enabled in the Flask backend using Flask-CORS.
Specifically, the following configuration was added to the Flask backend (app.py):
from flask_cors import CORS app = Flask(name) CORS(app) # Enables CORS for all routes and origins
This allows the frontend JavaScript code to successfully communicate with the backend API without browser security restrictions.