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: Docker Compose reads compose.override.yaml without being asked

Docker
~/tips/tip-docker-compose-override-file-auto

services:

Keep local changes in a second file that Compose merges on top automatically.

If a folder holds both compose.yaml and compose.override.yaml, a plain docker compose up loads the two of them. The override file is merged on top of the main one.

That makes it a good home for things that only belong on one machine: a debug flag, a bind mount to your source code, an extra port. The main file stays clean and can go into git, and the override can stay out of it.

# compose.override.yaml
services:
  web:
    environment:
      DEBUG: "1"
    volumes:
      - ./src:/app/src

Single values like DEBUG are replaced. Lists such as ports and volumes are added to what the main file has, so you end up with both sets.

To see what Compose really builds from the pair, I’d run:

docker compose config

The automatic loading stops the moment you pass -f. With docker compose -f compose.yaml up the override file is ignored, and you have to name it yourself as a second -f. That trips people up in scripts and CI jobs: the stack behaves differently there, and the override file is the reason. If an override should never be picked up by accident, give it another name and load it on purpose.

Further reading: Merge Compose files

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