Chapter Eight
Docker Compose
Everything done by hand so far — a created network, a named volume, and three docker run commands in the right order — collapses into one compose.yaml that brings the whole Driftwood stack up with a single command. This chapter is the Layer A finish line: a declarative file you keep instead of a script you re-run, with the database waited on until it actually accepts connections and a clean dev/prod split.
By the end of Chapter 7 the Driftwood stack worked, but only as a fragile sequence: create driftwood-net, create driftwood-db-data, then three docker run invocations with the right ports, env, mounts, and --network flags, in the right order, every time, on every machine. One skipped flag and the stack comes up wrong, and nothing records what "right" was. Docker Compose replaces that script with one declarative file you version next to the code it runs.
This chapter takes Driftwood from a page of README commands to git clone && docker compose up. You will learn the file model — services, networks, volumes — fix the startup race where web connects before Postgres is listening, separate container environment from compose-file interpolation, toggle optional services with profiles, and layer a prod override on a dev base. Throughout, one fact stays fixed: Compose manages one host. When production means many hosts, the answer is Kubernetes, not a taller stack of Compose files.
Topics in This Chapter
up idempotent, one project gets one network for free, and the single-host scope that ends where Kubernetes begins.image vs build, the default network's free name resolution, and Driftwood's three services declared in one file.depends_on waits for container start, not readiness. Healthchecks plus condition: service_healthy, and why app-side retry is still required.environment:/env_file:) versus .env interpolation in the compose file, the precedence order, and the secret-in-.env leak.up, activating a profile per invocation, and where profiles end and override files begin.compose.override.yaml that quietly shapes dev, explicit -f composition for a deterministic prod bring-up, and the single-host ceiling.up --build, aggregated logs, exec into a running container, down vs down -v, and live sync with compose watch.