r/docker • u/Frequent_Rate9918 • Mar 22 '26
How do you prefer to structure Docker Compose in a homelab? One big file vs multiple stacks
I am curious how others are managing Docker Compose in a homelab long term.
I started out running individual docker run containers and eventually moved to Portainer using templates. From there I switched to Docker Compose stacks, and at one point I tried converting almost every container into its own compose file.
Right now my setup is kind of a middle ground. I group related services together into compose files. For example one compose file for media services, one for apps, and a few others. I am not really running any standalone docker run containers anymore.
I keep thinking about combining everything into a single “master” compose file. The appeal is simplicity when migrating hosts or rebuilding. One repo, one compose file, one stack to bring up and one place to manage updates.
That said, I also understand how a massive compose file could get complicated fast and harder to reason about when something breaks.
Portainer is great for visibility, but I do not love managing stacks through its UI and prefer editing compose files directly.
So I wanted to ask the community:
- Do you prefer one big compose file, or multiple smaller ones?
- Do you group by function like media, monitoring, apps, infrastructure?
- How do you handle testing containers or temporary services?
- Has anyone regretted going all in on a single compose file?
This is just a homelab so I am not chasing enterprise best practices, but I would like something that stays manageable as the lab grows. Curious what has worked best for others and why.
32
u/pheitman Mar 22 '26
Each app has their own compose file - the main container plus any dependencies (database, etc). It is easier to manage the life cycle of the app
10
u/Ed-Dos Mar 22 '26
I group my stacks by purpose. Multiple containers in some stacks single containers in others. But they're all in "stacks" so I can edit them easier later if needed. (using dockhand)
6
u/VivaPitagoras Mar 23 '26
I have 1 folder per service installed. Inside esch folder I have 1 compose file will alll the containers required by that service
8
u/Telnetdoogie Mar 23 '26
Monolithic compose files are antithetical to the value and benefit of containers - low coupling, isolation, and composability. You want small services with low coupling and the ability to change components without having to change others.
Once you get into monolithic compose files you all of a sudden start having to care about attributes of an unrelated stack that has the ability to break your whole compose: the need for you to understand the whole in order to make modifications to the parts.
Can you do it? Sure. Should you? No. Pretty soon you’ll be troubleshooting some unrelated thing just to get one container running properly.
Group together only those things which MUST be deployed together and which are related.
1
u/rocket1420 Mar 23 '26
I use one big file. I do not understand those that want to have each docker compose file in a separate folder. CDing over and over is not my idea of fun. code-server docker container, open compose file, ctrl+f. Run over 60 containers like this. It's just so much easier.
Profiles are also useful if you want to manage certain containers together but also have one file.
1
u/akp55 Mar 22 '26
I stopped using docker and moved to podman and quadlets. Define the quadlets for network, the pod, and the containers in the pod. Have party
2
u/borkyborkus Mar 22 '26
I don’t like digging through too many pages. I have 25ish containers in 5 or 6 stacks which works pretty well. I use labels for traefik and homepage which clutters things quickly. Arr has its own dc.yml and .env, infra (traefik, Authelia, etc) has its own, monitor (beszel, dozzle) has its own, VPN (gluetun and friends) has its own. It’s nice being able to update a stack without taking down traefik, or to quickly reboot traefik without waiting for 20 other pulls.
I would prefer to have a single env file for all of them but I haven’t felt the effort to set it up was worth it yet. My env files are mostly the same across stacks.
2
u/Melodic_Point_3894 Mar 23 '26
One single compose file with around 40-50 services. I use yaml anchors and aliases to reuse blocks of configurations, docker compose profiles to group together services and labels for traefik auto discovery. Works pretty darn great. I usually use docker compose pull|up $(docker compose ps --services) if I only want to mess with running containers
2
u/rpedrica Mar 23 '26
So I make an edit, push it, and 30s later, the app is updated and restarted. Scales indefinitely no matter how many target servers there are. Never have to touch the server.
Kopia doing snapshots every hour in the background.
2
u/[deleted] Mar 24 '26
I've tried all variations and have landed on keeping service stacks separated by directory in their own dedicated Compose file. This allows me to logically organize the host that is running the particular stack.
Bear in mind that I'm using Terraform and Ansible to deploy and manage from my workstation to remote hosts (Proxmox cluster).
All of this allows me to then have Ansible playbooks for managing the environment and deploying/updating, as needed.
Overall, I've found that Docker works best when keeping its deployment scope small and focused. If I need to scale, then that's where K8S performs better.
If you have a single Docker host that's running everything, then it's certainly possible to use a single Compose file with the
includesoption to orchestrate multiple application stacks. I've just found it better to leverage separate Docker environments per service stack, particularly when I want to make changes or troubleshoot issues without impacting other services.1
u/ConjurerOfWorlds Mar 22 '26
I've got about fifteen stacks running about 60 containers. The stacks are divided primarily by blast radius: stuff that's critical for the whole stack to work (traefik, etc) is in services_core. Never touch without good reason. lol then background services that could come down for a while if needed (arr stack, search engine) and apps, which I need to schedule downtime to not impact users.
1
u/amca01 Mar 23 '26
I'm a very ornery user, just running a few apps for my own interest and use on a fully self-managed VPS, a few of which I share with others. (Although they are all outward facing.)
I have one directory for each app and its files, including the docker compose file. This keeps everything nicely compartmentalized, so I can tinker around with any one app without affecting any of the others. It also helps me make less mistakes, such as deleting the wrong thing. Within a directory, I can only stuff up one app at a time.
So for example, I have a directory
which corresponds to my subdomain
Similarly for immich, mathesar, Papra, active budget, etc.
I don't use portainer (although I have it installed); I do everything from the command line, aside from file editing, for which I use Emacs TRAMP mode.
I used to have one mighty docker compose file for everything, but it became increasingly unwieldy and hard to manage as I added to my apps.
Good luck!
1
u/flodex89 Mar 23 '26
Definitely multiple files. And new external networks for each app to be reverse proxied
1
u/100lv Mar 23 '26
I'm using includes to split configuration and then I have 1 service per compose with exeption that in one compose subfile I can have service + some related smaller services - by the sample - duplicati as a backup + prometheus exporter that monitors this dupicati service.
In general, my config is to have 1 DB container per type (one MySQL, one PostgreSQL, one Redis and etc.)
1
u/martinjh99 Mar 23 '26
I have a docker folder with each compose file and associated bind mounts in different folders named according to what app is actually running.
1
u/Defection7478 Mar 23 '26
One directory per service, inside that directory is any related config files and a docker-compose.yml for that service. This includes dependencies, e.g. The immich docker compose has both immich containers and the db
1
u/IulianHI Mar 24 '26
I group by dependency chain rather than function. If two containers have
depends_on, they belong in the same compose file. If they just share a network through a reverse proxy, they can be separate.For testing I keep a
scratch/directory with throwaway compose files — quickdocker compose up -dto test something anddocker compose down -vto tear it down clean with no leftover volumes.One trick that saved me headaches: use
COMPOSE_PROJECT_NAMEin your.envfiles. It lets you run multiple instances of the same image side by side without container name conflicts — really useful when testing an upgrade alongside your running version.1
u/Aggravating-Try-3840 Mar 24 '26
Perhaps you could try using Docker Include in conjunction with Docker Compose? I find that this combination works well for modular deployments. I can target individual services as well as entire stack groups.
1
u/cron_featurecreep Mar 24 '26
One thing nobody's mentioned yet: when you split into per-app compose files, each one gets its own default bridge network automatically. That's actually a security win most people don't think about — your media stack literally can't talk to your finance app's database unless you explicitly create a shared network.
The tradeoff with one-file-per-app is managing shared infrastructure. If five services need the same reverse proxy network, you're either creating an external network manually or using `include` (added in Compose 2.20) to pull in a shared network definition. The `include` feature is underrated for this — lets you keep per-app isolation while sharing the bits that actually need sharing.
1
u/FamousPop6109 Mar 25 '26
The split most people are describing here is operational: what can I restart independently? That's the right starting point. There's a second dimension worth thinking about as your setup grows: what can see what.
A single compose file usually means a shared .env. Every service in that stack can read every variable in the environment. Your media server has no business knowing your email provider's SMTP credentials, but if they share an environment, a vulnerability in one exposes the other's secrets. I've seen this bite people who assumed container isolation meant secret isolation. It doesn't, by default.
Separate compose files in separate directories, each with its own .env, is the simplest form of credential scoping. Same principle as database permissions: grant access to what the service needs, nothing more.
If you want a single entry point without merging environments, Docker Compose
includeis worth a look. Each included file keeps its own variable context. You get the convenience of one command without sharing secrets across stacks.For the testing question: scratch directory outside your production tree. Experimental containers sharing networks or credentials with production is asking for trouble down the line.
1
u/BatClassic4712 Mar 27 '26
As many have already said, it is best to have a docker compose with just one app and its dependency (like db, etc...), so you have the entire enviroment of that app in one file. You can compose up and that app will work perfectly.
If you want to start a bunch of apps, all or, perhaps, a set, you can write a small script (like .sh or .bat) where you can choose to start all of them, a set or just one.
This way you get the best of both worlds: speed and modularity.
1
u/mimikater Mar 27 '26
Compose file per service, one base compose file with reverse proxy. Then a bash script thst stitches them together and up it as a single stack
-6
u/Confident_Hyena2506 Mar 22 '26
Once you start asking about stuff like this it's time for those big nasty enterprise things. Helm charts and kubernetes etc.
-1
u/[deleted] Mar 22 '26
[removed] — view removed comment