Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

use inheritance in docker-compose.yml

I have a lot of services, which use the same basic configuration in docker-compose. Actually most of the configuration is the same, with some minor tweaks.

I have seen that it is somehow possible to inherit values in YAML. Can I use this in docker-compose to define a "default-service" and use this all over in the other services for e.g. docker-compose run? How would I do this?

like image 898
Mandragor Avatar asked Oct 31 '22 03:10

Mandragor


1 Answers

No, you cannot do that using YAML. The only inheritance like feature in YAML is the Merge Key Language Independent Type and that only works withing one YAML document, not between multiple documents in the same YAML file (separated by ---) and certainly not between different YAML files.

However docker-compose reads docker-compose.yml and if available docker-compose.override.yml, where the values in the second file (if available) override the ones in the first. Combined with the -f option to specify an input YAML file for docker-compose you can use a shared base file with different overrides.

This is a feature of docker-compose and is done on the data loaded from the YAML files, not by combining the YAML files and then loading them.

like image 106
Anthon Avatar answered Nov 15 '22 05:11

Anthon