Where’s the best place to store Docker Compose files and container data?

0
12
Asked By TechyTurtle42 On

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

Answered By DevGuru99 On

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.

Answered By DockerDude245 On

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.

Answered By StackMaster3000 On

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.

Answered By QuestionAuthor On

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

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.