{"id":21116329,"url":"https://github.com/sohailsajid79/python-flask-redis-multi-container-powerhouse","last_synced_at":"2026-04-11T15:36:39.631Z","repository":{"id":248300576,"uuid":"827036765","full_name":"sohailsajid79/Python-Flask-Redis-Multi-Container-Powerhouse","owner":"sohailsajid79","description":"The repository contains a simple multi-container application built with Flask and a Redis database, managed using Docker Compose. The Flask app uses Redis for data storage and retrieval.","archived":false,"fork":false,"pushed_at":"2024-07-14T10:55:05.000Z","size":324,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-21T04:42:40.714Z","etag":null,"topics":["docker","docker-compose","python3","redis"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sohailsajid79.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-07-10T22:31:24.000Z","updated_at":"2024-10-13T15:03:46.000Z","dependencies_parsed_at":"2024-11-20T02:27:33.822Z","dependency_job_id":"fb471278-a50b-41f5-b5d0-6f84793afba9","html_url":"https://github.com/sohailsajid79/Python-Flask-Redis-Multi-Container-Powerhouse","commit_stats":null,"previous_names":["sohailsajid79/python-flask-redis-multicontainer-app","sohailsajid79/python-flask-redis-multi-container-powerhouse"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sohailsajid79%2FPython-Flask-Redis-Multi-Container-Powerhouse","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sohailsajid79%2FPython-Flask-Redis-Multi-Container-Powerhouse/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sohailsajid79%2FPython-Flask-Redis-Multi-Container-Powerhouse/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sohailsajid79%2FPython-Flask-Redis-Multi-Container-Powerhouse/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sohailsajid79","download_url":"https://codeload.github.com/sohailsajid79/Python-Flask-Redis-Multi-Container-Powerhouse/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243565404,"owners_count":20311700,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["docker","docker-compose","python3","redis"],"created_at":"2024-11-20T02:26:14.954Z","updated_at":"2025-12-29T15:51:51.489Z","avatar_url":"https://github.com/sohailsajid79.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Python Flask Redis Multicontainer App\n\nThe repository contains a multi-container application that consists of a simple Python Flask web application and a Redis database. The Flask application uses Redis to store and retrieve data. This setup is managed using Docker Compose.\n\n## Table of Contents\n\n- [Project Overview](#project-overview)\n- [Architecture](#architecture)\n- [Setup Instructions](#setup-instructions)\n- [Docker Configuration](#docker-configuration)\n\n## Project Overview\n\nThe goal of this project is to create a multi-container application with the following features:\n\n- **Flask Web Application**:\n  - GET `/`: Displays a welcome message.\n  - GET `/count`: Increments and displays a visit count stored in Redis.\n- **Redis Database**: Used as a key-value store to keep track of the visit count.\n- **Dockerised Services**: Both Flask and Redis services are containerised.\n- **Docker Compose**: Used to manage the multi-container application.\n- **Persistent Storage for Redis**: Configured to use a volume to persist its data.\n- **Environment Variables**: Flask application reads Redis connection details from environment variables.\n- **Scaling**: The Flask service can be scaled to run multiple instances with load balancing.\n- **Nginx as Reverse Proxy and Load Balancer**: Nginx is used to route requests to the Flask instances, providing load balancing and acting as a reverse proxy.\n\n## Architecture\n\n![Python](https://img.shields.io/badge/Python-blue?logo=python) ![Flask](https://img.shields.io/badge/Flask-lightgrey?logo=flask) ![Docker](https://img.shields.io/badge/Docker-blue?logo=docker)\n![Redis](https://img.shields.io/badge/Redis-red?logo=redis)\n\n**Python** is chosen for this project due to its simplicity, readability, and extensive support for various libraries and frameworks.\n\n**Flask** is a lightweight and flexible web framework for Python that allows developers to create web applications quickly.\n\n**Docker** is used for containerisation, which packages the application and its dependencies into a consistent and isolated environment. This ensures that the application runs the same way regardless of where it is deployed.\n\n**Redis** is an in-memory data structure store that is used as a database, cache, and message broker. It is chosen for this project to handle the page view count due to its high performance, scalability, and ease of use.\n\n![ui_app](./assets/diagram.png)\n\n### Application Endpoints\n\nWelcome Page: `http://localhost:5002`\n\n![ui_app](./assets/:hello.png)\n\nVisitor Count: `http://localhost:5002/count`\n\n![ui_app](./assets/:counter.png)\n\n## Setup Instructions\n\n### Prerequisites\n\n- Docker / Docker Desktop\n- Docker Compose\n\n### Clone the Repository\n\n```bash\ngit clone https://github.com/sohailsajid79/python-flask-redis-multicontainer-app.git\ncd python-flask-redis-multicontainer-app\n```\n\n### Directory Structure\n\npython-flask-redis-multicontainer-app/\u003cbr\u003e\n├── app.py\u003cbr\u003e\n├── requirements.txt\u003cbr\u003e\n├── Dockerfile\u003cbr\u003e\n├── docker-compose.yml\u003cbr\u003e\n└── nginx.conf\n\n## Docker Configuration\n\n### Dockerfile\n\n```bash\nFROM python:3.11 # base image for docker container\n\nWORKDIR /app # set working directory inside of container\n\nCOPY requirements.txt requirements.txt # copy requirements file from local machine to conatiner's working directory\n\nRUN pip install -r requirements.txt # install dependencies inside container\n\nCOPY . . # copy application code to the container directory\n\nENV FLASK_APP=app.py # set env variable to target app.py\n\nCMD [ \"flask\", \"run\", \"--host=0.0.0.0\", \"--port=5000\" ] # default command to run when the container starts\n```\n\n### docker-compose.yml\n\n```bash\nversion: \"3.8\" # utilise latest version of docker compose\nservices:\n\n  redis:\n    image: \"redis:alpine\" # lightweight version of redis image\n    ports:\n      - \"6379:6379\" # map local port: container port\n    volumes:\n      - redis-data:/data # mount volume to '/data' inside container\n\n  flask:\n    depends_on: # create dependency on redis service\n      - redis\n    deploy:\n      replicas: 3 # scale the flask service to multiple instances\n    build: # directory containing the dockerfile to build the image\n      context: . # (root)\n    ports:\n      - \"5000\" # expose flask app on port 5000 inside the container\n    environment:\n      - REDIS_HOST=redis # flask app connect to the redis service using the hostname redis\n\n  nginx: # load balancer for the flask instances\n    depends_on: # create dependency on flask service\n      - flask\n    image: nginx:alpine # lightweight version of nginx image\n    volumes:\n      - ./nginx.conf:/etc/nginx/nginx.conf # mount local 'nginx.conf' file : '/etc/nginx/nginx.conf' inside the container\n    ports:\n      - \"80:80\" # map port 80 (local host): port 80 in container - nginx server to handle http requests from the host\n\nvolumes:\n  redis-data: # ensure that data stored in redis persists even if the container is stopped or removed\n```\n\n### Useful Docker \u0026 Bash commands\n\n- Check Docker is running: `docker info`\n- Stop and remove containers: `docker-compose down`\n- Start / restart docker service: `docker-compose up -d`\n- Scale flask service using --scale: `docker-compose up --build --scale flask=3`\n- Build Docker image manually: `docker build -t \u003cimage_name\u003e .`\n- Check running containers: `docker ps`\n- Check port usage: `lsof -i :\u003cport\u003e`\n- Kill process: `kill -9 \u003cPID\u003e`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsohailsajid79%2Fpython-flask-redis-multi-container-powerhouse","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsohailsajid79%2Fpython-flask-redis-multi-container-powerhouse","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsohailsajid79%2Fpython-flask-redis-multi-container-powerhouse/lists"}