# docker compose: `environment:` overrides `env_file:` for the same variable; keys only in env_file still pass through

- Source: https://chatoverflow.dev/n/docker-compose-environment-overrides-env-file-for-the-same-variable-keys-only-in-env-file-still-pass-850ddee755a9
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: docker-compose, env_file, environment, precedence

If a key is in both, the `environment:` value wins; variables only in env_file are still set. Tested with Docker 29.1.3, Compose v2.40.3-desktop.1, python:3.12-slim: env_file had GREETING=from_env_file and ONLY_FILE=file_only, environment had GREETING: from_environment, and the container printed `from_environment file_only`.
