GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - Mullah98/flask-redis-docker-app: A Flask web app fully containerised with Docker, using Redis to track and store page visits.. Tracks page visits with a /count page, demonstrates persistent Redis storage, and uses environment variables for configurable setups.

BranchesTags
Open more actions menu

Latest commit

 

History

1 Commit
1 Commit

Folders and files

NameName
Last commit message
Last commit date
assets
assets
 
 
.gitignore
.gitignore
 
 
Dockerfile
Dockerfile
 
 
README.md
README.md
 
 
app.py
app.py
 
 
docker-compose.yml
docker-compose.yml
 
 
requirements.txt
requirements.txt
 
 

Repository files navigation

Flask + Redis Docker App

This is a simple multi-container application built with Flask and Redis, fully dockerized. Page visits are counted are stored using the Redis database connected with the Flask service.

  • What it does:
    • / -> Displays a welcome message.
    • /count -> Displays the number of visits using Redis as a key-value store.

Demo

Demo


Features

  • Simple visit counter using Redis
  • Multi-container setup with Docker Compose
  • Fully containerised, can run anywhere Docker is installed

Stack

  • Python 3.8 + Flask
  • Redis
  • Docker / Docker Compose

Project Structure

my-flask-redis-docker-app/
│
├── app.py           # Flask app, defines routes and Redis logic
├── requirements.txt # Python dependencies
├── Dockerfile       # Defines Flask container setup
├── docker-compose.yml # Defines multi-container setup with Flask + Redis
└── README.md 

Setup Instructions

1. Clone the repo:

git clone <repo-url>
cd my-flask-redis-docker-app

2. Build and run the containers:

docker compose up --build

3. Access the app:

  • Open your web browser:
    • Welcome page -> http://localhost:5000
    • Count page -> http://localhost:5000/count

4. Stop the app:

docker compose down

Environment Variables

To make the app more production-ready in other environments without changing the code, we use environment variables.

In the docker-compose.yml file:

environment:
    - REDIS_HOST=redis
    - REDIS_PORT=6379

The Flask app reads these in app.py:

import os
from redis import Redis

redis_host = os.getenv('REDIS_HOST', 'redis')
redis_port = int(os.getenv('REDIS_PORT', 6379))
redis = Redis(host=redis_host, port=redis_port)

Challenges faced:

  • Issue: Initially tried using a multi-stage Dockerfile to keep images lean, but ran into COPY --from=build issues that caused Flask not to find the files.
  • Solution: Fixed the copy order which fixed the problem, but reverted back to a single-stage Dockerfile since the project is small and the extra complexity was not needed.

About

A Flask web app fully containerised with Docker, using Redis to track and store page visits.. Tracks page visits with a /count page, demonstrates persistent Redis storage, and uses environment variables for configurable setups.

Topics

dockerdocker-composedockerfileflaskpythonredis

Resources

Readme
Activity

Stars

0 stars

Watchers

0 watching

Forks

0 forks
Report repository

Contributors

Languages

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.