Something Neat in docker compose

So I was trying to figure out where to start and came across a neat functionality that's somewhat recently been added to docker compose, which is the include function. Normally when you want to create multiple containers that are all related you would either create them in separate projects in different directories or you would add them all to your docker-compose.yaml file.

The first option isn't ideal because then you have multiple folders with docker compose files in them and to get everything up and running you have to go into each and run docker compose up. Not a huge burden to be fair but still an inconvenience, and one that's now no longer necessary!

Alternatively, managing everything in one huge docker compose file is not great because the file can get kind of big and unwieldy leaving you searching through many services to get to the one you are trying to edit. This, when done poorly, is not how docker compose files are intended to be used, they are meant to group the necessary services for a single project, not span multiple loosely related projects.

Enter the include directive. Now if you have, for example, multiple web apps that are all provided through an nginx reverse proxy. You can have one docker compose file to setup nginx, and then another docker compose in either a sub directory or another project directory (for example either /opt/docker/nginx/{webapp1,webapp2} or /opt/docker/{nginx,webapp1,webapp2}). Then at the top of the nginx docker compose you include the docker compose files for the web apps and it will build it all for you in one go.

Managing disparate and smaller docker compose files can still be a good method if you want an easy way to only take down part of setup. But even that isn't as necessary as it may seem since you can docker compose down webapp, specifying the service in the docker compose file you are wanting to act on.

I'm glad this function is finally implemented, I remember looking around for it a while ago when I was learning docker compose because it just made sense for it to exist to me. I look forward to seeing what else they improve on and add in the future. Next time maybe I'll write about monitoring for a home lab... once i get the monitoring built out and where I want it heh.