I'm trying to figure out when it's best to combine services in Docker Compose instead of separating them into different files. For example, I have two services, 'flotsam' and 'jetsam', and I can set them up in a single compose file or separate files. Why would I choose to combine them? What are the upsides and downsides to bundling services like this? I'm also new to Docker, primarily interested in simple self-hosted projects using others' images from Docker Hub. I'd appreciate any insights!
2 Answers
I've found it helpful to keep one application or domain per compose file. For instance, if an app relies on a database, I group them together. This way, once it's running, I can restrict outside access to the database while still allowing the app to communicate with it. The only time I might split them is when using an HTTPS proxy that connects to multiple stacks, so I can handle certificates in one place.
Combining services can be beneficial if the containers rely on each other and need to start simultaneously. It simplifies management while making sure everything needed is launched together. Plus, Docker Compose will automatically create a default network for all services in a stack, which is convenient. If everything is well-defined, you'll also need to write less overall.
Just a correction: the `depends_on` feature works in the same stack, not just within the same file. You can still use `include` with multiple files.

That's a really clear answer. Thank you for breaking it down!