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
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)
app.py
A simple Flask application that connects to Redis to count the number of hits on the page.
Dockerfile
Defines how to build the Docker image for the Flask application:
requirements.txt
.docker-compose.yml
Sets up two services:
requirements.txt
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! 🎉