217 cards
A Docker Compose file is a YAML document that describes a multi-container application. In Compose v2, the modern format no longer requires a top-level version: field; the schema is inferred from the features you use. The top-level keys you'll encounter are services, networks, volumes, secrets, configs, and name. Inside...
The depends_on: key controls the order in which Compose starts services, but it has a sharp edge that catches almost everyone the first time. The short form depends_on: [db, redis] and the long form with condition: service_started only wait for the container to be created and started, not for the service inside that co...
Compose supports three flavors of persistent storage, and choosing the right one matters. A bind mount maps a host path into the container, written as ./local:/app, with optional read-only mode :ro or a consistency mode like consistency: cached for macOS performance. Bind mounts are ideal for source code in development...
Every Compose project gets a default network named <project>_default, and on that network services can resolve each other by service name. That name resolution is what makes the line depends_on: db actually useful: when your app says db:5432, it reaches the database container, not the host. This is also the most...
The build: key tells Compose how to construct an image for a service. The simplest form is just a path to a directory containing a Dockerfile, but a richer form lets you specify the context separately from the dockerfile, so you can keep the Dockerfile named differently per environment. To pass build-time variables, us...
One of Compose's most powerful features is the ability to split a configuration across multiple files and merge them. The conventional layout is a base docker-compose.yml containing the shared services, a docker-compose.override.yml that is automatically merged on top for local development, and a docker-compose.prod.ym...
Debugging a Compose project starts with the docker compose ps command, which shows the status of every service, and the docker compose logs command, which prints container output. To follow logs in real time, add -f; to scope to one service, pass its name: docker compose logs -f web; to scope to multiple services, list...
For Postgres, the canonical Compose service sets POSTGRES_USER, POSTGRES_PASSWORD, and POSTGRES_DB environment variables to create a database on first run, mounts a named volume on /var/lib/postgresql/data for persistence, mounts SQL or shell files into /docker-entrypoint-initdb.d/ for one-time initialization, and defi...