$ show twtrubiks/docker-tutorial
This repository is an educational Docker tutorial centered on a functional Django REST API application. The core implementation uses Docker Compose to orchestrate two services: a Django web container (DRF) and a PostgreSQL container, with explicit health checks, JSON-file logging limitations, named volumes, and user-defined networks. The Django API itself is a basic music CRUD service with endpoints under /api/musics, secured behind authentication, and housed in a straightforward project structure that demonstrates the typical pattern of a containerized Python microservice. Beyond the main tutorial, the repo provides stand-alone Docker Compose examples covering advanced patterns: YAML anchors to reduce configuration repetition, docker-compose override to batch operate multiple databases, environment variable substitution with .env files, profiles for selective service boot, and cAdvisor for container resource monitoring. Each subfolder includes a README and ready-to-run configuration, making the entire repository a one-stop teaching resource for Docker Compose patterns and best practices. The code is not intended as a production tool but rather as a self-contained, reproducible learning blueprint that shows how to build and manage containerized stacks with modern features. While the application layer is deliberately simple, the Docker-compose layer embodies several good practices around health and logging, and the advanced usage of YAML anchors and overrides exemplifies high-quality configuration craftsmanship that is directly reusable in other projects.
The LLM identified 3 files worth highlighting for reuse:
Demonstrates the YAML Anchors feature to define a shared base configuration (image, restart, logging, volumes) with the `&-` & `<<` merge key. This allows three nginx service clones to avoid repetitious declarations. It also highlights that merged array keys (volumes) are overwritten by the service-level definition, so to retain the base volumes one must re-add them manually β a non-obvious gotcha. The pattern is directly usable in any multi-service Docker Compose project to reduce YAML maintenance.
A Bash script used as the Docker container entrypoint. On each startup it runs Django migrations (`makemigrations` + `migrate`) and creates a admin auth superuser only if not already present (tamed via `--noinput`). After initialization, it executes the main container command (`exec "$@"`). The script encapsulates the 'run-time initialization' pattern that many image require: it's clear, idempotency, and can be adapted for any framework needing schema migrations during startup .
A bash script that iterates over a list of Odoo databases and for each one sets an environment variable (`DB_NAME`) and runs `docker compose up -d` with a corresponding override file. This enables batch application of Odoo addons across multiple databasesβeach usage overrides the command stand-ins for the web service. The script is a reusable pattern for any scenario that uses compose-file overrides combined with environment variable interpolation to run multiple iterations of a changed services with different parameters.