Level: Beginner
Estimated time: 1 week
Skills: Docker, Docker Compose, container security basics, environment-based configuration, GitHub Actions, image scanning
AWS services: Amazon ECR (optional)
ShopNest has a small internal API called orders-report. It is a Python Flask app that reads order data from PostgreSQL and returns daily sales summaries to the finance team. One developer wrote it three years ago, and it only runs on that developer's laptop.
Last month that developer went on leave and the finance team could not get their reports for a week. A second developer tried to run the app and lost two days to problems like these:
- The app needs a specific Python version that is not written down anywhere.
- Some dependencies are installed globally on the original laptop and missing from
requirements.txt. - The database host, user and password are hard-coded in
config.py. - PostgreSQL must be installed locally with a particular version and a manually created database.
- Nobody knows which operating system packages the app needs.
The engineering lead wants the app containerized so any developer can run it with one command, and so it can later move to a container platform. The security team asked that images be scanned before they are published.
Package orders-report as a secure, small container image and provide a Docker Compose setup that runs the app with PostgreSQL locally. Build a GitHub Actions pipeline that builds the image, scans it with Trivy, fails on critical vulnerabilities and pushes passing images to a registry tagged with the git commit SHA.
You can write your own simple Flask (or Node.js) API with two or three endpoints that read and write to PostgreSQL. The app itself is not graded. The packaging is.
- Docker Desktop or Docker Engine with Compose v2 installed locally. No AWS account needed unless you choose ECR.
- A GitHub account (GitHub Container Registry is free for public repositories).
- Comfortable with: running a Flask or Express app locally, environment variables, basic SQL.
- Day 1: small app with
/healthand two endpoints, config from environment variables, works locally. - Day 2: multi-stage Dockerfile, non-root user, HEALTHCHECK,
.dockerignore; record both image sizes. - Day 3:
compose.yamlwith PostgreSQL, named volume, health checks and.env.example. - Day 4 to 5: GitHub Actions build, Trivy scan, SHA-tagged push on
main; capture a failing scan. - Day 6 to 7: evidence, README, clean-machine test, then open
change-request.md.
Milestones are a pacing guide, not extra requirements. Record the date you reach each one; it makes a better story for your README and your interviews.
- A Flask app with a
requirements.txtthat is incomplete. - Configuration, including the database password, hard-coded in source code.
- A local PostgreSQL install on one laptop with no setup script.
- No Dockerfile, no Compose file, no CI pipeline.
- No documentation on how to run the app.
Developers run the app and database together with Docker Compose. Configuration comes from environment variables. On every push, GitHub Actions builds the image, scans it with Trivy, and pushes it to a registry only if no critical vulnerabilities are found. Each image is tagged with the commit SHA it was built from.
- Uses a multi-stage build: dependencies are installed or built in one stage, and only what is needed at runtime is copied into the final stage.
- Uses a small base image (for example a
slimoralpinevariant, or a distroless image). Document your choice and the final image size. - Pins the base image to a specific version tag, not
latest. - Runs the app as a non-root user.
- Runs the app with a production server (for example Gunicorn for Flask), not the Flask development server.
- Defines a
HEALTHCHECKthat calls a health endpoint on the app. - Contains no secrets in
ENV,ARG, copied files or any image layer.
- A
.dockerignorefile excludes at least:.git,.envfiles, virtual environments, caches, test output and local editor files.
- All configuration (database host, port, name, user, password, log level) is read from environment variables.
- Hard-coded credentials are removed from the source code.
- The app exposes a
/healthendpoint that returns 200 when the app is running and can reach the database.
- A
compose.yamlfile runs the app and PostgreSQL together. - PostgreSQL uses a pinned official image version and stores data in a named volume.
- PostgreSQL has a health check, and the app only starts after the database is healthy.
- Values come from a
.envfile that is git-ignored. A.env.examplewith placeholder values is committed. - Only the app port is published to the host. The database is not exposed to the host unless you document why.
- A new developer can run the app with
docker compose upafter copying.env.exampleto.env.
- A GitHub Actions workflow runs on pull requests and on pushes to
main. - The workflow builds the image and scans it with Trivy.
- The workflow fails if Trivy finds any CRITICAL vulnerability.
- On
mainonly, a passing image is pushed to a registry and tagged with the full git commit SHA. - Registry choice:
- GitHub Container Registry: authenticate with the built-in
GITHUB_TOKENand grant only thepackages: writepermission the job needs. - Amazon ECR (optional): authenticate with GitHub OIDC and an IAM role limited to pushing to one repository. No AWS access keys in GitHub secrets. Enable scan on push and image tag immutability.
- GitHub Container Registry: authenticate with the built-in
- Third-party actions are pinned to a full commit SHA.
-
docker compose upon a clean machine starts both containers, and the app responds on its published port. -
docker compose psshows both containers as healthy. -
docker run --rm <image> id(or equivalent) shows a non-root user. -
docker history --no-trunc <image>anddocker inspect <image>show no passwords or secrets. - The final image size is documented and is smaller than a single-stage build of the same app (show both sizes).
- Data in PostgreSQL survives
docker compose downfollowed bydocker compose up. - Stopping the database makes
/healthreturn a non-200 response. - A pull request that introduces a base image or dependency with a known critical vulnerability fails the Trivy step.
- A merge to
mainpushes an image tagged with the commit SHA, visible in the registry. - The repository contains no
.envfile and no credentials.
- Do not commit secrets. Use
.envlocally and repository or environment secrets in GitHub Actions only where truly needed. - Do not run the container as root.
- Do not push images tagged only as
latest. - If you use AWS, no long-lived access keys. Use GitHub OIDC.
- Do not disable or skip the Trivy scan to get a green pipeline. Fix the finding or document an accepted risk in a
.trivyignorefile with a reason.
- Deploying the container to Amazon ECS, Amazon EKS or any server.
- Kubernetes manifests or Helm charts.
- A managed database such as Amazon RDS.
- Database migration tooling beyond a simple init script.
- Load testing and performance tuning.
In a real job, requirements change while you are building. This project has one change request. It is stored in change-request.md in this folder.
Do not read it until you have finished the main requirements (the last milestone above says when). Opening it early removes the point of the exercise, which is adapting a finished design to a new requirement.
- A GitHub repository with the app code,
Dockerfile,.dockerignore,compose.yaml,.env.exampleand the GitHub Actions workflow. - An architecture diagram that matches what you built.
- A project README with prerequisites, how to run locally, how configuration works, and how the pipeline works.
- Evidence for every acceptance criterion in an
evidence/folder, including a failed pipeline run caused by a critical vulnerability. - A short demo video (3 to 5 minutes) showing a fresh clone running with one command and a pipeline run pushing a SHA-tagged image.
- Pull request reviewed by at least one peer or mentor, or a completed self-review committed to the repository.
- All acceptance criteria checked and evidenced.
- Change request implemented and evidenced.
- A second person (or a clean virtual machine) has run the app from the README alone.
- Any cloud resources (for example an ECR repository) removed or kept with a lifecycle policy, and this is documented.
- Running Docker and Docker Compose locally has no cloud cost.
- GitHub Actions usage on GitHub-hosted runners is free for public repositories. Private repositories use your account's included minutes.
- Amazon ECR (if used) is billed for image storage per GB-month and for data transfer out. Add a lifecycle policy that expires old untagged images, and delete the repository with
terraform destroyor the AWS CLI when you finish. - Locally, run
docker compose down -vto remove containers and the database volume when you are done, and prune unused images.
- Docker multi-stage builds
- Dockerfile building best practices
- Compose startup order and health checks
- Trivy GitHub Action
- Working with the GitHub Container registry
Official documentation only. If a tool behaves differently from what this brief says, the documentation wins; open an issue so the brief can be corrected.
Containerized a laptop-only Flask and PostgreSQL service with a multi-stage, non-root Docker image and Docker Compose, cutting local setup from 2 days to under 10 minutes and reducing image size by 60%; added a GitHub Actions pipeline with Trivy scanning that blocks critical vulnerabilities and publishes SHA-tagged images.
Replace the numbers with your own real results.
- What does a multi-stage build give you, and what did you leave out of the final stage?
- Why should a container not run as root, and how did you set that up?
- How do you keep secrets out of a container image, and how would you check an image for leaked secrets?
- Why tag images with the git commit SHA instead of
latest? - What does the Compose health check and
depends_oncondition solve, and what does it not solve? - Your Trivy scan fails on a critical vulnerability in the base image. What are your options?
Part of Real DevOps Projects. Build it, push it to your own GitHub, and add it to your resume. Use the evidence template, the demo video guide and the self-review checklist.
