Docker Community Forums

Share and learn in the Docker community.

[feature request] docker-compose: grouping services


nice to meet you all.

I’d like to present you an idea that came in my mind in the latest weeks, as I’m dealing with a pretty large docker-compose configuration - there are many services.

To give you more detail, this compose configuration belongs to Laradock, a nice project which helps to setup a development environment, familiar to people working with php applications (eg. Laravel).

Being a generic tool, it’s coming with a very large amount of services, defined in the docker-compose file.

Once you know which services must be used, you can start them simply by their names:

docker compose up apache2 mysql workspace - a common execution command that I use.

There’s a catch: if you don’t specify explicitly each service to start, then ALL of them are started, we are talking about more than 50 services. So you must be careful, otherwise docker will download a lot of images, and start configuring them. If you don’t see this, then you will need some time to bring your local setup to where it was before.

In order to avoid this problem, and to avoid typing each service every time, I created a simple bash script.

Anyway, this story made me think about the possibility to assign each service in the docker-compose config, to a group, and consequently being able of running commands targeted to this group.

It’s true, one can create duplicate the configuration, adapt to the needs, and use that file… it works, but:

  • you must keep every config in “sync”
  • some docker-compose.yml files are very “intricate” and hard to split into smaller files
  • assigning a service to a group would be more fluid, almost like linking it to a network

It’s not the main goal, but having groups could allow to run services in a certain sequence:

  • infrastructure group: apache2, mysql (launch first)
  • app group: my application (wait infrastructure group launch)

What do you think about it?


Would profiles suit your need? See Using profiles with Compose | Docker Documentation. (That would also avoid starting all of the services when forgetting to be specific.)