I recently started migrating my self-hosted services to docker
. To simplify maintenance, I'm using docker-compose
. Some of the containers depend on each other, others are independent.
With more than 20 containers and almost 500 lines of code, maintainability has now decreased.
Are there good alternatives to keeping one huge docker-compose
file?
That's a big docker-compose.yml! Break it up into more than one docker-compose file.
You can pass multiple docker-compose files into one docker-compose
command. If the many different containers break up logically, one way of making them easier to work with is breaking apart the docker-compose.yml
by container grouping, logical use case, or if you really wanted to you could do one docker-compose file per service (but you'd have 20 files).
You can then use a bash alias or a helper script to run docker-compose
.
# as an alias
alias foo='docker-compose -f docker-compose.yml -f docker-compose-serviceA.yml -f docker-compose-serviceB-yml $@'
Then:
# simple docker-compose up with all docker-compose files
$ foo -d up
Using a bash helper file would be very similar, but you'd be able to keep the helper script updated as part of your codebase in a more straightforward way:
#!/bin/bash
docker-compose -f docker-compose.yml \
-f docker-compose-serviceA.yml \
-f docker-compose-serviceB.yml \
-f docker-compose-serviceC.yml \
$@
Note: The order of the -f <file>
flags does matter, but if you aren't overriding any services it may not bite you. Something to keep in mind anyway.
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