Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lahcenezzara/composedemo
Lab: Setting up a Multi-Container Architecture with Docker Compose
https://github.com/lahcenezzara/composedemo
api backend cloud containerization devops docker docker-compose dockerfile flask microservices multi-container python python3 redis scalable-architecture web-application web-server
Last synced: 6 days ago
JSON representation
Lab: Setting up a Multi-Container Architecture with Docker Compose
- Host: GitHub
- URL: https://github.com/lahcenezzara/composedemo
- Owner: LahcenEzzara
- License: mit
- Created: 2024-10-24T10:41:45.000Z (about 2 months ago)
- Default Branch: main
- Last Pushed: 2024-10-24T10:43:49.000Z (about 2 months ago)
- Last Synced: 2024-12-17T00:13:42.959Z (6 days ago)
- Topics: api, backend, cloud, containerization, devops, docker, docker-compose, dockerfile, flask, microservices, multi-container, python, python3, redis, scalable-architecture, web-application, web-server
- Language: Python
- Homepage: https://lahcenezzara.github.io/composedemo/
- Size: 3.91 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Docker Compose Flask & Redis App
This project demonstrates a simple Python web application built with Flask and Redis, using Docker Compose to set up a multi-container architecture.
## Project Structure
```
composedemo/
│
├── app.py # Flask application
├── Dockerfile # Dockerfile to build the web app
├── docker-compose.yml # Docker Compose configuration
└── requirements.txt # Python dependencies
```## Prerequisites
- Docker installed on your machine.
- Docker Compose installed.## Getting Started
Follow these steps to set up and run the project locally.
### 1. Clone the Repository
```bash
git clone https://github.com/LahcenEzzara/composedemo.git
cd composedemo
```### 2. Define the Flask Application
The main Flask application logic is in `app.py`. It uses Redis to count the number of times the page has been accessed.
### 3. Define Dependencies
The `requirements.txt` file lists the necessary dependencies for the Flask app:
```
flask
redis
```### 4. Build and Run the Containers
Use Docker Compose to build and run the application:
```bash
docker compose up
```The application will be accessible at [http://localhost:8000](http://localhost:8000). Every time you refresh the page, the counter increments.
### 5. Stop the Application
To stop the running containers, use the following command:
```bash
docker compose down
```## Updating the Application
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:
```python
return 'Hello from Docker! I was here {} times.\n'.format(count)
```## File Descriptions
### `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:
- Uses Python 3.7 Alpine.
- Installs necessary dependencies from `requirements.txt`.
- Exposes port 5000 for the Flask app to run.### `docker-compose.yml`
Sets up two services:
- **web**: Runs the Flask application.
- **redis**: Uses the official Redis Alpine image.### `requirements.txt`
Specifies the Python dependencies for the Flask app:
- `flask`
- `redis`## Rebuild the Application
If you need to rebuild the application after making changes, you can do so with:
```bash
docker compose up --build
```## License
This project is open source and available under the [MIT License](LICENSE).
---
Happy coding! 🎉