Typing -f compose.yaml -f compose.prod.yaml before every logs, ps and exec gets old fast, and forgetting it once means you talk to a different setup. COMPOSE_FILE remembers the list for you.
On Linux and macOS the files are separated by a colon. Later files are merged on top of earlier ones, just like repeated -f flags.
export COMPOSE_FILE=compose.yaml:compose.prod.yaml
docker compose config --services
docker compose up -d
My favourite place for it is the project’s .env file. Compose reads that file for its own settings too, so the line below makes every command in that folder use the production pair without any exported variable:
# .env
COMPOSE_FILE=compose.yaml:compose.prod.yaml
The separator is a colon on Linux and macOS and a semicolon on Windows. You can change it with COMPOSE_PATH_SEPARATOR if you share the setting across systems.
An explicit -f on the command line still wins over the variable. That is handy for a one-off, but it also means a script with its own -f ignores your carefully chosen list. When something behaves oddly, docker compose config shows which files and values were really used.
Further reading: Compose environment variables: COMPOSE_FILE