Skip to content
Latchkey

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 directory

Common 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

  1. 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 -d

Mark the env file optional (Compose 2.24+)

  1. If the file may be absent, declare it optional so compose tolerates it.
docker-compose.yml
services:
  web:
    env_file:
      - path: .env.ci
        required: false

How to prevent it

  • Create env files from secrets in CI before compose up.
  • Use required: false for env files that may legitimately be absent.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →