Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker Compose: Should I have multiple docker-compose files?

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?

like image 267
L H Avatar asked Jul 13 '20 07:07

L H


2 Answers

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

  • It will not create unnecessary container
  • It will avoid port conflict ( in case two sharing same port)
  • Will save compute cost
  • Less time to create a docker-compose stack
  • More manageable

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.

like image 59
Adiii Avatar answered Sep 28 '22 04:09

Adiii


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.

like image 31
MichaPoe Avatar answered Sep 28 '22 02:09

MichaPoe