Sensible folders and permissions for Docker selfhosting?

I'm running a Raspberry Pi 4 with an external SSD to provide a few services (right now: Photoprism, The Lounge, Miniflux, planned: paperless-ng). I need to re-install the system to upgrade from Raspberry Pi OS based on Debian buster to bullseye. In addition I plan to switch to the 64-bit version because I encountered multiple problems with Docker. (Some other processes are caddy for reverse proxy, restic for backups and sshd for remote access.) Currently only Photoprism is a docker container but in the new setup I want to use containers for all applications.

Currently the disk is mounted in one directory (/srv/data) and used to store application data in various folders, everything uses mostly one user account, file permissions and ownership are inconsistent.

Since I am upgrading the operating system its time to fix that!

  1. Should I combine the various docker-compose files from various services into one large file?
  2. Is it recommended to create a new user account on the host for each service and let the service create files with that service?
  3. Where to mount the drive? (I considered the home directory, but I don't want the system fail to boot if the drive is disconnected.)
  4. What's a good directory layout for the Docker volumes? Photoprism and paperless-ng have an import directory, so they should be accessible for a low priviledge user for upload.
  5. How is the sudoer account best configured? I use it to manage the services and make manual changes?

If there is a sort of best-practices document for home server setup and security with Docker I am grateful for a link as well.

Posted Jan 6, 2022, 9:10 PM UTC

46
JustSub•
  1. Yeah, this is what I do. It’s a long file, but I like having it all in one file.
  2. Meh. I don’t think this is necessary. I trust file system name spacing. Just make one non-root user account. Both namespaces and permissions are kernel features, and I don’t know enough to think one is more trustworthy than another.
  3. I use /media/primary/<servicename> for all my services. I don’t see an issue with /home/username/mountname though.
  4. See 3. If a single service needs multiple mounts, I put them as subdirectories.
  5. You need a sudoer to control docker unless you use rootless docker, which I highly recommend! Other than running docker-compose you probably won’t use it much.

Here’s a link to my full config, which is really close to what you’re trying to do. https://github.com/subdavis/selfhosted

You can look at my photoprism as an example. The docker compose file is alphabetized.

2
pyfischOP•

Thanks for the explanation. Rootless Docker seems to be a bit of a hassle to configure. Perhaps I can use podman instead?

I will definitely consult your docker-compose file.

1
JustSub•

It’s not that bad, but all up to personal preference of course. You can’t really use podman instead because many of these containers rely on the docker socket API.

If you want to use caddy or traefik or Nginx proxy, it’s not an option.

2
Haquestions4•

I'd advice not to put everything into a single file. If you want to update or backup a single container, would you need to take/risk taking everything down?

Put things together that depend on each other. That way you'll have less downtime.

1
pyfischOP•

I think you can update and restart the containers in a docker-compose file one-by-one: https://stackoverflow.com/a/61362893 So far I didn't have the need to back up containers, they can be easily recreated and I just backup the volumes and code to setup the machine.

1
Haquestions4•

Yes, you can, but I don't want the administrative overhead of deciding which version of which container is the right one to stop if I can just take the stack down completely since the containers depend on each other anyway.

I didn't mean back up containers, I meant back up volumes. No way I am borgbackup'ing a database that is still running.

2