Coolify was auto-injecting env_file: [".env"] into every service in Docker Compose deployments, causing ALL environment variables to leak into EVERY container regardless of which service they were defined for.
Example of the security issue: In a Next.js + PostgreSQL + Redis stack, the Redis container has access to POSTGRES_PASSWORD and the PostgreSQL container can see OPENAI_API_KEY meant only for the app.
Per Docker Compose documentation, the .env file is used for YAML variable interpolation only (${VAR} substitution in the compose file), not for runtime environment injection into containers.
Three locations auto-injected .env into every service’s env_file:
bootstrap/helpers/parsers.php — Application parser flow (line ~1322)bootstrap/helpers/parsers.php — Service parser flow (line ~2421)app/Jobs/ApplicationDeploymentJob.php — Compose deployment (line ~640).env into env_file for all Compose servicesenv_file entries (if users explicitly add env_file: [my-custom.env] in their compose, it is preserved).env file generation for Docker Compose YAML variable interpolation (unchanged).env)Each service now only receives environment variables from its own environment: section, which is already populated per-service by the parsers with the correct variables.
POSTGRES_PASSWORD for postgres, API_KEY for app)docker exec into each containerenv | grep POSTGRES_PASSWORD in the app container should return nothingenv | grep API_KEY in the postgres container should return nothing${SERVICE_*} variable interpolation in compose YAML still worksenv_file: entries in compose are preservedUsers who relied on the implicit behavior of all env vars being shared across all containers will need to explicitly add variables to each service’s environment: section or use env_file: in their compose file. This is the correct Docker Compose behavior.
cwanglab
@cwanglab
Tom Adamczewski
@tadamcz