docker compose stops with 'invalid interpolation format' on a value that contains ${...}
Invalid interpolation format for "environment" option in serviceShort answer
Compose reads $VAR and ${VAR} in every value. A braced expression that is not a valid variable name or a supported form, such as ${server.port} or ${VAR/a/b}, stops it with invalid interpolation format. Write the dollar sign twice ($$) so Compose leaves the text alone, then run docker compose config to see the result.
Fix it fast
1Find out which cause you have
Let Compose resolve the file on its own, without starting anything. The error names the path of the value it choked on, for example services.app.environment.SERVER_URL.
docker compose config2Match what you see, then jump to its fix
- 1
invalid interpolation format for services.<name>.<option>.<KEY>, and the value printed under it holds something like ${server.port}, ${env:HOME} or ${VAR/old/new}A ${...} placeholder is meant for the app or the shell, not for ComposeFix - 2
No error. The value inside the container is shorter than it should be, and docker compose config prints a warning that a variable is not setA password, hash or command with $name inside is silently changedFix - 3
The compose file is fine, but the value read from .env arrives cut shortThe same secret comes from a .env fileFix
- 1
What does the error look like?
Invalid interpolation format for "environment" option in serviceinvalid interpolation format for services.app.environment.SERVER_URL.You may need to escape any $ with another $.
Cause 1 of 3
A ${...} placeholder is meant for the app or the shell, not for Compose
1Check
List every braced dollar expression in the file. Compose accepts only ${VAR}, the default forms ${VAR:-x} and ${VAR-x}, the required forms ${VAR:?msg} and ${VAR?msg}, and the replacement forms ${VAR:+x} and ${VAR+x}. The name must start with a letter or an underscore and contain only letters, digits and underscores, so a dot or a slash makes the expression invalid. Extended shell features such as search and replace are not supported.
grep -n '\${' docker-compose.yml compose.yaml 2>/dev/null2Fix
Double the dollar sign in front of every placeholder that is not a Compose variable. Compose turns $$ into one $ and does not expand what follows it.
services:
app:
image: my-app:latest
environment:
# the app expands its own placeholder at run time
SERVER_URL: "http://localhost:$${server.port}/api"
command: sh -c 'echo "$$HOME"'3Verify
Compose resolves the file, and the printed value carries a single dollar sign.
docker compose config | grep -E 'SERVER_URL|command'Confirmed by docs.docker.com
Cause 2 of 3
A password, hash or command with $name inside is silently changed
1Check
A dollar sign followed by letters is a variable reference. If no such variable exists, Compose warns and substitutes an empty string, so pa$word loses everything from the dollar sign to the end of the name. Generated passwords and password hashes can be hit this way, because they often contain a dollar sign followed by letters.
docker compose config 2>&1 | grep -i -E 'not set|DB_PASSWORD'2Fix
Escape the dollar sign in the compose file the same way, with two of them.
services:
db:
image: postgres:17
environment:
# wanted value: pa$word
POSTGRES_PASSWORD: "pa$$word"3Verify
The resolved value matches the secret and the warning is gone.
docker compose config | grep POSTGRES_PASSWORDConfirmed by docs.docker.com
Cause 3 of 3
The same secret comes from a .env file
1Check
Unquoted and double-quoted values in .env are interpolated as well. Only single-quoted values are used literally, and the .env next to the compose file feeds Compose's own substitution.
grep -n '\$' .env2Fix
Put the value in single quotes in the .env file.
# .env
DB_PASSWORD='abc$def'3Verify
Compose prints the full value.
docker compose config --environment | grep DB_PASSWORDConfirmed by docs.docker.com
How do I stop it coming back?
- Run docker compose config in CI before docker compose up, so a bad expression fails the pipeline and not the deploy.
- Keep generated secrets in single quotes in .env, or hand them over as Docker secrets instead of pasting them into the compose file.
- When a command needs the container's own variables, write them with $$ from the start.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Servers
Docker Compose ignores the values in my env file
the variable is empty inside the container
Compose has two separate env mechanisms.
4 causes, each with a fixServers
Compose does not see the $PWD variable in my volume path
Compose warns that a variable is not set and substitutes an empty string
Compose fills ${PWD} from the environment of the shell that runs it, not from the shell's own idea of the current folder.
3 causes, each with a fixServers
apk cannot find py-pip in an Alpine Docker image
py-pip (no such package):
On current Alpine releases there is no package called py-pip.
2 causes, each with a fixServers
ng serve runs in the container but localhost:4200 does not open
The browser cannot open localhost:4200 although ng serve is running in the container
ng serve listens on localhost by default, which inside a container is the container itself.
3 causes, each with a fixServers
Angular routes return 404 from nginx when you refresh or open a link
The home page loads, but refreshing /some/route shows an nginx 404
Angular routes like /users/42 are not files, so nginx looks for them on disk and returns 404.
3 causes, each with a fixServers
AH00558: Apache in Docker cannot reliably determine its fully qualified domain name
Set the 'ServerName' directive globally to suppress this message
AH00558 is a warning, not a crash.
2 causes, each with a fix