With ${VAR:?text} a compose.yaml makes a variable mandatory. If it is missing or empty, nothing starts, and the message names the service, the variable and your hint. The most common cause: Compose reads a different source than you think.
Symptom
NOTES_API_KEY= docker compose up -d worker error while interpolating services.api.environment.NOTES_API_KEY: required variable NOTES_API_KEY is missing a value: NOTES_API_KEY fehlt (.env)
Here the key is deliberately set to empty in the shell. The same message appears when .env is not read. “fehlt” is the German hint text from the compose.yaml (“missing”).
Diagnosis
The compose.yaml marks the variable as required; the hint after :? becomes part of the message.
NOTES_API_KEY: ${NOTES_API_KEY:?NOTES_API_KEY fehlt (.env)}
Causes
${VAR:?text}Required variable empty or unset
:? stops if the variable is missing or empty; ? without the colon only if it is missing.
--env-fileWith --env-file Compose no longer reads .env
With only --env-file interval.env, .env is no longer read – the key is missing. Compose reads several --env-file in order; later ones override earlier ones.
docker compose --env-file interval.env up -d worker error while interpolating services.api.environment.NOTES_API_KEY: required variable NOTES_API_KEY is missing a value: NOTES_API_KEY fehlt (.env)
shellThe shell beats every file
An empty variable in the shell hides the value from .env – even one exported by accident.
Fix
docker compose --env-file .env --env-file interval.env up -d worker Container notes-worker-1 Recreated
Don't: Remove the required check so it starts – the service then runs with an empty key and fails later in a less obvious place.
Docker Compose hands-on, Day 4: configuration with variables, .env, --env-file and defaults.
Go to day 4 →
FAQ
What is the difference between ${VAR:-std} and ${VAR-std}?
:- uses the default also when the variable is empty, - only when it is missing.
In which order does Compose interpolate values?
Shell variables first, then files from --env-file, and without --env-file the .env in the project folder.