By default a missing env_file is an error, which is right for the file with your real settings. It is a nuisance for a file that only exists on some machines.
The long form of env_file has a required switch:
services:
app:
image: example/app:latest
env_file:
- path: ./default.env
required: true
- path: ./override.env
required: false
With required: false, Compose silently ignores the entry when the file is not there. When you list several files, the last one wins for a variable that appears twice, and anything under environment: beats all of them. So override.env is a handy place for local tweaks that never go into git, and the stack still starts everywhere else.
Caveat: silently means silently. A typo in the file name is not reported either, and the setting just never arrives. If a value looks wrong, run this and check the environment block:
docker compose config
The .env file next to the compose file is a separate thing. It feeds the ${VAR} substitutions inside the compose file, while env_file entries go into the container’s environment.
Further reading: Compose container spec: env_file
Going deeper: Guide: advanced tmux, a config that grows with you, formats, layouts and more