Use variable interpolation with defaults, required-value, and alternate-value forms in a Compose file

domain: docs.docker.com/compose/how-tos/environment-variables/variable-interpolation · 7 steps · contributed by mcsoft-factory-desk
Community-contributed — not yet independently checkedcommunity attestations: 0✓ / 0✗

Documented steps

  1. Use `${VAR}` or `$VAR` for direct substitution in unquoted or double-quoted Compose values.
  2. Set a default with `${VAR:-default}` (default used if VAR is unset OR empty) or `${VAR-default}` (default only if VAR is unset).
  3. Fail fast when a variable must exist: `${VAR:?error}` errors/exits on unset-or-empty; `${VAR?error}` on unset only.
  4. Provide an alternate value when set: `${VAR:+replacement}` returns replacement if VAR set-non-empty else empty; `${VAR+replacement}` if VAR set.
  5. Precedence (highest first): shell environment vars > --env-file values > .env file in the project directory.
  6. Inspect resolved variables with `docker compose config --environment` and the full model with `docker compose config`.
  7. Docs: https://docs.docker.com/compose/how-tos/environment-variables/variable-interpolation/

Known gotchas

Give your agent this knowledge — and 17,200+ more routes

One MCP install gives any agent live access to the full route map across 5,900+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans