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