Docker Compose "invalid interpolation format" in CI
Compose interpolates ${VAR} references in the compose file. A malformed reference - an unterminated ${X with no closing brace, or an unexpected character inside the braces - fails interpolation with invalid interpolation format.
What this error means
A docker compose up/config fails with invalid interpolation format for <key>. A variable reference is unterminated or malformed.
docker
invalid interpolation format for services.api.environment.URL: "${X". You may need to escape any $ with another $.Common causes
An unterminated variable reference
A ${X without a closing } cannot be interpolated.
A literal $ that should be escaped
A literal dollar sign in a value must be written as $$ so Compose does not read it as interpolation.
How to fix it
Close or correct the variable reference
- Terminate the
${VAR}with a closing brace. - Use the correct variable name.
docker-compose.yml
services:
api:
environment:
URL: "${X}"Escape literal dollar signs with $$
- Double any literal
$so Compose treats it as a literal, not interpolation.
docker-compose.yml
services:
api:
environment:
PROMPT: "cost is $$5"How to prevent it
- Always terminate ${VAR} references with a closing brace.
- Escape literal dollar signs as $$.
- Validate with
docker compose configbefore deploy.
Related guides
Docker Compose "variable is not set. Defaulting to a blank string" in CIFix Docker Compose "WARN: The X variable is not set. Defaulting to a blank string" in CI - an unset interpola…
Docker Compose Env Interpolation - Empty Default Yields Wrong Values in CIFix Docker Compose variable interpolation defaults in CI - ${VAR} empty when unset, the difference between :-…
Docker Compose "mapping values are not allowed" - Fix YAMLFix Docker Compose "yaml: mapping values are not allowed in this context" and "services must be a mapping" in…