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 -f a.yaml -f b.yaml merges files in order

Docker
~/tips/tip-compose-multiple-f-override

docker compose -f compose.yaml -f compose.prod.yaml up -d

Combines several compose files in order, so a small file can override parts of the base file.

One compose file for the stack and a second small one for the changes on a particular machine keeps the main file clean. The order of the -f flags is the whole trick.

Compose merges the files in the order you give them, and later files can merge into, override or add to earlier ones. The first file is the base, and relative paths in every file are resolved from the base file’s location.

docker compose -f compose.yaml -f compose.prod.yaml up -d

The docs describe how the merge works. Single-value options like image or command are replaced by the later file. Lists such as ports and expose are concatenated. environment and labels merge by name, with the override winning, and volumes merge by mount path.

A small override could look like this:

services:
  app:
    image: example/app:2.0
    ports:
      - "8081:80"

Before running anything, look at the result with docker compose -f compose.yaml -f compose.prod.yaml config. It prints the merged file, so you see what Compose will really do.

Mind the default: with no -f, Compose reads compose.yaml and also compose.override.yaml if it exists in the same folder. as soon as you pass -f yourself, you decide the list, so add the override file yourself when you want it.

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