This project demonstrates a simple Python web application built with Flask and Redis, using Docker Compose to set up a multi-container architecture.
composedemo/
│
├── app.py # Flask application
├── Dockerfile # Dockerfile to build the web app
├── docker-compose.yml # Docker Compose configuration
└── requirements.txt # Python dependencies
- Docker installed on your machine.
- Docker Compose installed.
Follow these steps to set up and run the project locally.
git clone /~https://github.com/LahcenEzzara/composedemo.git
cd composedemo
The main Flask application logic is in app.py
. It uses Redis to count the number of times the page has been accessed.
The requirements.txt
file lists the necessary dependencies for the Flask app:
flask
redis
Use Docker Compose to build and run the application:
docker compose up
The application will be accessible at http://localhost:8000. Every time you refresh the page, the counter increments.
To stop the running containers, use the following command:
docker compose down
The docker-compose.yml
file includes a bind mount that allows live updates to the code. Any changes made to the app.py
file will automatically apply to the running container without needing to rebuild the image.
If you modify the code, simply refresh the page to see the changes:
return 'Hello from Docker! I was here {} times.\n'.format(count)
A simple Flask application that connects to Redis to count the number of hits on the page.
Defines how to build the Docker image for the Flask application:
- Uses Python 3.7 Alpine.
- Installs necessary dependencies from
requirements.txt
. - Exposes port 5000 for the Flask app to run.
Sets up two services:
- web: Runs the Flask application.
- redis: Uses the official Redis Alpine image.
Specifies the Python dependencies for the Flask app:
flask
redis
If you need to rebuild the application after making changes, you can do so with:
docker compose up --build
This project is open source and available under the MIT License.
Happy coding! 🎉