What this thread does
The problem
Your app reads a variable that is set in a local env file, but under Docker Compose it is empty, or Compose prints The XUSER variable is not set. Defaulting to a blank string.
What the sources say
- Stack Overflow, "Docker-Compose Environment-Variables blank string". The accepted answer (acran) says the root misunderstanding is mixing two features:
env_fileinjects variables into the container's environment, while${VAR}substitution in the compose file reads the environment of the machine running Compose (or a.envfile in the current directory). His fix: move the file to.envfor substitution, and addenvironmententries if the container needs them too. Another answer (mxlhz) shows--env-fileon the command line, and saysdocker-compose confighelps to see what Compose resolved. - A third answer (patricknelson) reports that after a Docker Desktop 4.12.0 upgrade, double-quoted values containing
$in anenv_filewere treated differently and single quotes fixed it. That is one user's report, not verified here. - Docker's Compose environment variables docs (read October 2026):
environmentsets variables in the compose file;env_fileloads them from files (several files evaluated in order, later override earlier); a bare variable name passes it from the shell;${VAR}interpolation uses shell or.envvalues and warns when a variable is missing;docker compose run -esets one for a single run. The page states that interpolation in.envfiles is a Compose CLI feature.
Order of things to try
1. Decide which job you need: a placeholder in the compose file (.env or shell) or a variable inside the container (env_file or environment). 2. Run docker compose config and read the resolved output. 3. Inside the running container, print the one variable (docker compose exec <service> env), not the whole environment. 4. Check quotes and $ characters in the env file.
How to describe it to your agent
The variable <NAME> is blank in my container. Run docker compose config and show me the resolved value for that service. Explain whether I am using .env substitution or env_file, and fix it with the smallest change. Do not print or paste secret values.
Mistakes to check
- Expecting
env_fileto fill${VAR}in the compose file itself. - Committing a real
.envfile with secrets. - Printing the whole container environment in logs.
Limits
I did not run these steps. The accepted answer dates from 2020 and uses the older docker-compose command; the docs page is current.
Started from a post by @acran, mxlhz, patricknelson (Stack Overflow); Docker documentation, packaged by the editor. Original post