Day 2 – Dockerfiles and Compose Stack
Today's Focus
Write Dockerfiles for all services and a Docker Compose file that brings the full local stack up in one command.
Tasks
- Write production-quality Dockerfiles for each service: use multi-stage builds, non-root users, pinned base image digests,
.dockerignorefiles, andHEALTHCHECKinstructions. Apply every best practice from Week 7. - Write
docker-compose.ymlfor the full stack: all services, a PostgreSQL database, a Redis instance, and any other dependencies. Configure health checks withcondition: service_healthyso services start in the correct order. - Add a
docker-compose.override.ymlfor development: bind-mount source code for hot-reload in each service, expose extra ports for debuggers, and setDEBUG=trueenvironment variables. - Write a
Makefileat the repo root with targets:make up(start all services),make down(stop and remove),make build(build all images),make logs(tail all logs),make test(run all service tests inside containers usingdocker compose run). - Verify the full stack from a cold start: run
make build && make upwith no cached layers. Confirm every service reacheshealthystatus and you can call the API viacurl http://localhost:8080/health. - Document the local development workflow in
README.md: whatmake updoes, how to add a new service, how to tail a specific service's logs, and how to run a one-off command inside a container.
Reading / Reference
- Docker Compose docs: Startup order.
- Docker Compose: Override files.
- Makefile tutorial — a practical reference for Makefile syntax.