brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: COMPOSE_FILE sets which Compose files load, so you can stop typing -f

Docker
~/tips/tip-docker-compose-file-env-var

docker compose config --services

Pick the set of Compose files once through an environment variable.

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

More Docker tips ONBUILD RUN /usr/local/bin/python-build --dir /app/src SHELL ["/bin/bash", "-c"] docker commit <container> myname/testimage:version3 docker import /path/to/exampleimage.tgz docker compose events All Docker tips (192) All topics

Link