I'm setting up a homelab and looking for some best practices for managing my Docker setup. Specifically, I have two main questions:
1. Where should I keep my docker-compose and YAML files? I plan to use GitHub for version control, but I'm unsure about the best filesystem location for these files. I've used my home directory in the past, but I'm open to suggestions for better options.
2. What's the best way to store container data? I've typically mounted volumes per container, but I still need advice on the filesystem structure for that data. Should I back it up using OS tools, or is there a better method using Docker commands?
4 Answers
Honestly, for the first question, it doesn't matter at all. But for storing container data, I suggest using bind mounts while you're developing. It makes file modifications easier, especially if you're using something like VSCode.
If you're setting it up for production and don't need to tweak the files regularly, consider using Docker volumes instead. They're straightforward—just give your volume an arbitrary name in your docker-compose file, and you won't have to worry about the filepath. For backups, you can use commands like 'docker cp' or mount the volume in another container.
For your first question, it really doesn't matter too much where you store those files. You can keep them in your home directory if that's what you're comfortable with.
As for the second question, I'd recommend using bind mounts. Just create a directory in /opt for each service; it keeps things organized and easy to manage.
A clean setup for me would be something like /opt/stacks/ where I create a folder for each compose project. I like to keep a Git repo in that stacks directory to version-control all my files.
I typically use bind mounts because Docker handles permissions well, and it's easier to access the data directly when needed. I also run something like 'dockhand.pro' for a GUI touch. And if you’re using a Mac, 'Orbstack' is pretty awesome for managing things.
Thanks for the tips! Just to clarify, is a "compose project" the same as a stack? Since I have three areas I'm working on—home automation, media, and network—can I use the include directive to manage my YAML files better?
For example, can I create a single file at /opt/stacks/the_whole_shebang.yaml that includes the other specific compose files for each project? Would it work to have a shared database service for both my home automation and media projects this way?

Related Questions
How To Get Your Domain Unblocked From Facebook
How To Find A String In a Directory of Files Using Linux