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: the include element pulls another compose file into yours

Docker
~/tips/tip-compose-include

include:

Pulls other compose files into your main one so a big stack can be split into smaller files.

When a stack grows, I would rather split it into a few files than scroll through one huge one. The top-level include element does that without extra command line flags.

You list the files in the main compose.yaml:

include:
  - my-compose-include.yaml

services:
  serviceA:
    build: .
    depends_on:
      - serviceB

The included file declares serviceB, and serviceA can depend on it as if it were defined locally. Each included file is loaded as its own Compose application with its own project directory, so relative paths in it resolve correctly from where that file lives. The mechanism is recursive: an included file that has its own include brings in those files as well.

If you need to change something in an included file, the path entry can take a list where the second file overrides the first:

include:
  - path:
      - third-party/compose.yaml
      - override.yaml

Unlike several -f flags, this needs no extra typing from whoever runs the stack: they just use docker compose up. The docs also mention that included files can come from remote sources such as OCI artifacts or Git repositories.

A conflict is an error: if a resource in the main file clashes with one from an included file, Compose reports it and does not guess. Rename it, or use an override file in the include entry.

Further reading: Include

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