I have a project with components base on Docker and orchestrated with docker-compose
. Some of them are optional, and can be added at runtime.
I can think about two ways to achieve that:
serviceA.yml
compose file and run it as a separate projectserviceA
to my base compose.yml
and run it againWhat is the preferred option to do that?
I've also seen that you can combine docker-compose
files with the extend
keyword, but I don't think this can fit, since I have a variable number of services that I can add at runtime.
I usually end up having multiple yml files.
Then you can add several -f flags to docker-compose command to indicate which services to run.
For instance, having:
You can execute to start:
docker-compose -f docker-compose.yml -f docker-compose-additional-services.yml up
And it will start all services.
Note, that all services are merged as if they were in a single file, so you can reference (depends_on, link) services from one file to the other.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With