Multi-Container Application — Flask + Redis
Built a two-service containerized application: a Python Flask web app exposing a welcome route and a live visit-counter route, with Redis acting as the in-memory key-value store holding the counter across requests.
The problem
A web application that keeps state in its own process loses that state the moment the container restarts or scales. The counter needed to live outside the app container, in a dedicated data service the app reaches over the container network rather than over a hardcoded address.
What I built
- 01
Wrote a Flask application with two routes: / rendering the dashboard and welcome view, and /count incrementing and reading a visit counter stored in Redis.
- 02
Containerized the app with a slim python:3.11-slim Dockerfile — WORKDIR, COPY, pip install flask redis, EXPOSE 5003 and a CMD entrypoint.
- 03
Declared both services in docker-compose.yml: a redis:7-alpine service started with --requirepass and its port published, and the built web service with depends_on ordering.
- 04
Passed REDIS_HOST, REDIS_PORT and REDIS_PASSWORD as environment variables so the Flask container resolves the database by service name through Compose's internal DNS instead of an IP address.
- 05
Configured a Redis volume for persistent storage so the counter survives container restarts, then verified live increments by refreshing /count.
Project stages
01 / 05
Stage 01 — Dockerfile for the Flask service: python:3.11-slim base, dependencies installed, EXPOSE 5003 and the app entrypoint.