case study · containers
Docker Lab
UNDER CONSTRUCTION
A hands-on containers lab, built module by module: a 6-service Docker Compose platform (Flask API, async worker, PostgreSQL and two Redis) across 4 segmented networks, with hardened non-root images, two CI/CD pipelines that scan with Trivy and publish to GHCR, and full observability — metrics and centralised logs. Built to justify every decision, with 9 ADRs recording the trade-offs and the bugs I hunted down.
architecture
System architecture
A developer pushes code; GitHub Actions builds the images, scans them with Trivy and publishes them to GHCR — only what passes the gate, and only from main. The runtime runs on Docker Compose across 4 segmented networks: the Flask API answers in milliseconds with 202 Accepted and enqueues work in Redis, a horizontally scalable worker consumes it, and PostgreSQL persists the data with Alembic migrations. Prometheus and Grafana scrape metrics from the host, the containers and the app, and logs flow as JSON through Fluent Bit to Elasticsearch and Kibana.
overview
What it is & why I'm building it
Docker Lab is a progressive project: I build a small but realistic containerised system and evolve it stage by stage, so I can understand and defend every decision — from image layers to orchestration.
It runs six services on Docker Compose across four segmented networks — the data network has no route to the internet — and it is deliberately split by execution mode: an API that answers in milliseconds, a queue, and a worker that does the slow work.
Highlights
- Six services, four networks — Flask API, async worker, PostgreSQL and two Redis (sessions and queue), with the data network isolated from the internet.
- Hardened images — own images on python:3.13-slim, non-root user, patched base layer and a Trivy gate that blocks publishing.
- Async by design — 202 Accepted + Redis queue + scalable worker, with idempotency, backoff retries and clean SIGTERM shutdown.
- Two CI/CD pipelines — one per service: build → Trivy scan → publish to GHCR, tagged by commit SHA and with actions pinned by SHA.
- Observability from day one — metrics in 3 layers (host, container and app) with Grafana dashboards as code, plus centralised JSON logs.
engineering decisions
Key decisions
// why containers?
Reproducible everywhere
Compose describes the whole stack as code: the same environment on my laptop, in CI and in production. No «works on my machine».
// why harden images?
Small, safe images
Multi-stage builds keep images small; non-root users and vulnerability scans reduce the attack surface before anything ships.
// why a worker + queue?
Async by design
Splitting slow work into a worker behind a queue keeps the API responsive and lets each part scale independently.
// why split API and worker?
Split by execution mode
Not by domain: the API answers in milliseconds and returns 202 Accepted, while a worker without HTTP does the slow work. Each side scales on its own, and a duplicated message can't do duplicated work — idempotency is enforced by three chained mechanisms.
build status
The build plan, stage by stage
Built module by module, each with explicit “done” criteria. Four of the six modules are complete; the rest is an honest roadmap, not a claim.
// built · modules M0–M3
- Base stack: Flask API, worker, PostgreSQL and two Redis on Docker Compose
- Hardened images: non-root, patched base layer, .dockerignore and Trivy gate
- CI/CD per service (build → scan → GHCR), async worker and Alembic migrations
- Observability: metrics in 3 layers and centralised JSON logs
// next · not started yet
- Automated tests in the pipeline
- Kubernetes and IaC — planned, not started
tech stack
Stack & responsibilities
| Technology | Layer | Responsibility |
|---|---|---|
| Docker · Compose | Orchestration | Defines and runs the 6-service stack across 4 segmented networks. |
| Python · Flask | API | REST API and application logic. |
| PostgreSQL | Data | Relational persistence for the app. |
| Redis (x2) | Cache · Broker | Separate instances for sessions and for the job queue. |
| worker | Worker | Consumes queued jobs for async processing. |
| GitHub Actions | CI/CD | Builds, scans with Trivy and publishes images to GHCR. |
| Trivy · non-root | Security | Hardened images and a scan gate; third-party actions pinned by SHA. |
| Prometheus · Grafana | Monitoring | Metrics in 3 layers (node_exporter, cAdvisor, app) with dashboards as code. |
| Fluent Bit · Elasticsearch · Kibana | Logs | Centralised JSON logs correlated by request id. |
| Git · GitHub | Versioning | Everything versioned and documented, stage by stage. |
Follow the build
The repo documents each module with its ADRs and how to reproduce it — or get in touch to talk it through.