Currently, I have about 20 containers in the same docker-compose.yml file. Not all of the containers are related but it has been set up this way so I could just run docker-compose up
once to start all of the containers.
Should I be breaking it up into multiple docker-compose files (e.g. one application per docker-compose file, which could include multiple containers like a frontend + database)? Are there any significant drawbacks with having all of your containers in one huge docker-compose file?
Not all of the containers are related but it has been set up this way so I could just run docker-compose up once
If you keep all the container in single docker-compose.yml
file for the sake of this need, so then better to go for One project per docker-compose file instead creating all containers. as you can start multiple compose file at once also.
If you want to start all container then just pass
docker-compose -f docker-compose.projecta.yml -f docker-compose.projectb.yml up
Or for a single project
docker-compose -f docker-compose.projecta.yml
You can also explore expend option
Share Compose configurations between files and projects
I will go for One project per docker-compose file because
And the last when validating compose file is really messy as no proper line indication when there is error, so configuration error will only propagate to single project and it will not affect all the other project.
I actually had a very similar challenge on my current project. That broght me to the idea of writing a small script which I called docker-compose-profile
(or short: dcp
). I published this yesterday on GitLab as docker-compose-profile. So in short: I now can start several predefined docker-compose profiles using a command like dcp -p some-services "up -d"
. A profile may contain a subset of all defined services in your docker.compose.yml
. With this mechanism it would be easy to start up several sets of services defined seperately in a dcp.yml
.
Feel free to try it out and give some feedback or suggestions for further improvements.
To answer your question ... If all services belong to the same project You might keep them in one file. If not, split it to sepearat docker-compose.yml
files.
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