Allow multiple extends
Description
Why is there no option to extend multiple docker-compose.yml files? It would be useful if a company could define fragments of configuration, that then can be thrown in partially to any service, like:
services:
app:
extends:
- file: docker-compose.commons.yml
service: commons
- file: docker-compose.splunk.yml
service: logging
- file: docker-compose.hosts.yml
service: extra_hosts
IIUC you have docker-compose.hosts.yml set to "just" define a hosts attribute you want to reuse in other services ?
So, basically, you'd like to have support for yaml anchors from multiple files
I've got a better use-case - trying to make a server setup where it's easy for other people to take and use it themselves, where they can set an env var to turn chunks of the config on or off - which (so far) means enabling GPU access, and enabling different depends_on keys - then I can update the compose tree and push to git so it's easy to update.
Thanks to the broken (ie, doesn't copy -f) behaviour of include: I can't have multiple optional files that can be added by the user as an override - plus each individual service itself is also optional and while there is a core list that are all included in the main compose.yaml overriding that while allowing the user to override individual keys is not supported.
Showing the minimal ideal here - but there's also a need for network (if using a vpn), postgres (if not using sqlite) etc. An alternative would be allowing multiple service names within the extends - then each of those could in turn extend from a separate file... (Currently I'm faking something like the second one with longer service names that include all options in order)
Option 1: Multiple extends
services:
something:
# ...
extends:
- file: compose.cloudflared.yaml
service: ${USE_CLOUDFLARED:-false}
- file: compose.gpu.yaml
service: ${USE_GPU:-none}
# More to come...
compose.cloudflared.yaml
services:
true:
depends_on:
cloudflared:
condition: service_started
restart: false
false:
compose.gpu.yaml
services:
amd:
environment:
AMD_VISIBLE_DEVICES: "all"
nvidia:
environment:
NVIDIA_DRIVER_CAPABILITIES: "all"
NVIDIA_VISIBLE_DEVICES: "all"
none:
Option 2: Multiple services
services:
something:
# ...
extends:
file: compose.extends.yaml
service:
- "cloudflared-${USE_CLOUDFLARED:-false}"
- "gpu-${USE_GPU:-none}"
# More to come...
While feasible, such a feature would make the compose parser way more complex to manage the many overrides paths. Ability to "define fragments of configuration" is already well supported with yaml anchors, and should be preferred I'm closing this proposal as "not planned"