Docker
Local stack: PostgreSQL + Django API, orchestrated by a single docker-compose.yml at the repo root. The API image is built from backend/Dockerfile and boots via backend/entrypoint.sh.
[!info] Authority Stack versions and rationale live in [[adr-002-dev-stack|ADR-002]] / [[adr-002-a-backend-dev-stack|ADR-002-a]]. Environment variables live in [[adr-006-environment-variables|ADR-006]]. This page is operational only.
Services
Sección titulada «Services»| Service | Container | Image | Port (host → container) |
|---|---|---|---|
db | kdx-ng-db | postgres:16-alpine | 127.0.0.1:5432 → 5432 |
api | kdx-ng-backend-pod | built from backend/Dockerfile | 8000 → 8000 |
api depends on db being healthy. Both have healthchecks; api’s probe hits GET /api/health/.
Volumes
Sección titulada «Volumes»| Volume / mount | Purpose |
|---|---|
pg_data (named) | PostgreSQL data. Wiped by down -v. |
./backend:/app (bind) | Live source for hot-reload. Shadows the image’s copied code. |
/app/.venv (anonymous) | Keeps the container’s venv from being clobbered by the bind mount. |
./API.md:/API.md:ro | Contract file for the test suite ([[adr-005-a-contract-testing-pipeline |
[!note] Fixtures survive
down -vMock fixtures live under./backend/fixtures/and are part of the./backend:/appbind mount, so they are not removed bydown -v(which only drops thepg_datavolume). See [[mock-data|Mock Data]].
Boot sequence
Sección titulada «Boot sequence»entrypoint.sh runs on every container start (6 steps):
makemigrations+migratecreate_superuser(skipped ifSUPERUSER_PASSWORDis unset) — see [[admin|Admin]]- Local only:
loaddata fixtures/mock_clinic.yamlthenfixtures/mock_employees.yaml— see [[mock-data|Mock Data]] collectstaticflushexpiredtokens- Start server — uvicorn
--reload(local) or the production CMD
Steps 2 and 3 are idempotent across restarts (PK-keyed superuser get_or_create and fixture upsert).
Common commands
Sección titulada «Common commands»docker compose up -d # start (build on first run)docker compose up -d --build # rebuild the api imagedocker compose down # stop, keep datadocker compose down -v # stop, WIPE the databasedocker compose logs -f api # follow API logsdocker compose exec api python manage.py shell # Django shelldocker compose exec api pytest # run the test suitecurl http://localhost:8000/api/health/ # health check