Docker Compose "env_file path does not exist" in CI
A service env_file: loads variables from a file at parse/up time. In CI that file is often git-ignored (it holds secrets) and never recreated, so compose cannot find it. Generating the file from secrets or marking it optional resolves it.
What this error means
A docker compose up fails with env file /app/.env.ci not found or no such file or directory.
docker
env file /home/runner/work/app/app/.env.ci not found: stat /home/runner/work/app/app/.env.ci: no such file or directoryCommon causes
A git-ignored env file never recreated in CI
The .env.ci file is excluded from the repo and the workflow never writes it from secrets.
A wrong relative env_file path
The path is resolved relative to the compose file; a wrong directory makes it missing.
How to fix it
Generate the env file from secrets
- Write the env file from CI secrets before running compose.
Terminal
printf 'DB_URL=%s\nAPI_KEY=%s\n' "$DB_URL" "$API_KEY" > .env.ci
docker compose up -dMark the env file optional (Compose 2.24+)
- If the file may be absent, declare it optional so compose tolerates it.
docker-compose.yml
services:
web:
env_file:
- path: .env.ci
required: falseHow to prevent it
- Create env files from secrets in CI before
compose up. - Use
required: falsefor env files that may legitimately be absent.
Related guides
Docker Compose "env file not found" - Fix Missing env_file in CIFix Docker Compose "env file .env not found" in CI - a referenced env_file missing from the runner, wrong rel…
Docker Compose "env file ... not found" in CIFix Docker Compose "env file <path> not found" in CI - an env_file (or --env-file) path that does not exist r…
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…