Data in host folders
By default the database and the files live in Docker volumes. This guide keeps them in folders you choose instead, owned by one dedicated local user, and runs both containers as that user, so only it can read the data.
Named volumes work fine; choose host folders when you want the data on a particular disk, to back it up with your usual tools, or to keep it readable by one user only. Do this right after step 2 of the install, before the first start, or see Moving existing data.
Where everything goes
| Path | Holds | Owner |
|---|---|---|
/opt/homespace/compose.yaml | The compose file from the install guide, unchanged. | root |
/opt/homespace/compose.override.yaml | The changes below: folders and container user. | root |
/opt/homespace/.env | Secrets and settings, mode 600. | root |
/srv/homespace/db | The PostgreSQL files. | homespace, mode 700 |
/srv/homespace/files | The uploaded files and their versions. | homespace, mode 700 |
/etc/nginx/conf.d/homespace.conf | The site from the nginx guide. | root |
/srv/homespace is only an example
Put the data wherever suits you, for example /mnt/data/homespace on a separate disk. If you choose another location, use it everywhere this guide says /srv/homespace: when creating the folders, in the SELinux commands, and in HOMESPACE_DB_DIR and HOMESPACE_DATA_DIR in .env. The compose override needs no change, since it reads the folders from .env. Keep the database on a local disk, not on a network share.
1. Create the local user
A system user with no home and no login shell. It only owns the data:
sudo useradd --system --user-group --no-create-home --shell /usr/sbin/nologin homespace id homespace
id prints its uid and gid, for example uid=990(homespace) gid=990(homespace). The numbers differ per machine; the steps below read them with id -u and id -g.
2. Create the folders
Create both folders, owned by homespace and closed to everyone else:
sudo install -d -m 700 -o homespace -g homespace /srv/homespace sudo install -d -m 700 -o homespace -g homespace /srv/homespace/db /srv/homespace/files
With SELinux enforcing (Fedora, RHEL and their relatives), also allow containers to use them:
sudo semanage fcontext -a -t container_file_t '/srv/homespace(/.*)?' sudo restorecon -R /srv/homespace
Do not use the :Z volume option instead: on the /etc/passwd mount below it would relabel a system file.
3. Add the compose override
Download compose.override.yaml next to compose.yaml. Docker Compose reads a file with this name on its own and merges it into compose.yaml, so every command in the other guides stays the same:
cd /opt/homespace sudo curl -fsSLO https://home-space.app/docs/compose.override.yaml
# Home Space: keep the database and the files in host folders, owned by one local user.
# Guide: https://home-space.app/docs/host-folders/
#
# Put this file next to compose.yaml: docker compose reads compose.override.yaml on its own,
# so the usual commands stay the same (docker compose up -d, pull, logs ...).
#
# Add to .env:
# HOMESPACE_DB_DIR host folder for the Postgres files, e.g. /srv/homespace/db
# HOMESPACE_DATA_DIR host folder for the files, e.g. /srv/homespace/files
# HOMESPACE_UID uid of the owning local user (id -u homespace)
# HOMESPACE_GID gid of the owning local user (id -g homespace)
services:
db:
user: "${HOMESPACE_UID:?set HOMESPACE_UID}:${HOMESPACE_GID:?set HOMESPACE_GID}"
volumes:
- ${HOMESPACE_DB_DIR:?set HOMESPACE_DB_DIR}:/var/lib/postgresql
# Postgres looks its running user up by uid; an arbitrary uid has no passwd entry in the image.
- /etc/passwd:/etc/passwd:ro
server:
user: "${HOMESPACE_UID:?set HOMESPACE_UID}:${HOMESPACE_GID:?set HOMESPACE_GID}"
volumes:
- ${HOMESPACE_DATA_DIR:?set HOMESPACE_DATA_DIR}:/data- The folder mounts replace the
dbandfilesvolumes, because they use the same paths inside the containers. user:runs Postgres and the server ashomespaceinstead of the users built into the images, so the files they write belong to it.- Postgres looks its own user up by uid when it starts. The image has no entry for your uid, so the host's
/etc/passwdis mounted read-only.
If you prefer one file, copy the same user: and volumes: lines into the two services of compose.yaml and delete the volumes: block at its end.
4. Add the folders and the user to .env
Append the four values, reading the uid and gid from the user you created:
cd /opt/homespace sudo tee -a .env > /dev/null <<EOF # Data in host folders, owned by the homespace user # Your own locations, if you chose others HOMESPACE_DB_DIR=/srv/homespace/db HOMESPACE_DATA_DIR=/srv/homespace/files HOMESPACE_UID=$(id -u homespace) HOMESPACE_GID=$(id -g homespace) EOF
Check the merged configuration, then start as in step 3 of the install:
sudo docker compose config | grep -E 'user:|/srv/homespace' sudo docker compose up -d sudo docker compose logs -f server
Compose stops with set HOMESPACE_… if one of the four values is missing.
Check it
sudo ls -ln /srv/homespace/db /srv/homespace/files sudo docker compose exec server id
Everything in both folders should belong to the uid and gid of homespace, and the server should report the same numbers. If Postgres exits with Permission denied, the folder is owned by someone else or, on SELinux, is missing its label.
Back up
Dump the database as before, and copy the files folder with any tool you like:
cd /opt/homespace sudo docker compose exec -T db pg_dump -U homespace -Fc homespace > homespace-db.dump sudo tar -C /srv/homespace/files -czf homespace-files.tar.gz .
Copy /srv/homespace/db itself only while the database is stopped; the dump is the safe way while it runs.
Moving existing data
Already running with the named volumes? Stop the containers, copy the volumes into the folders, and give them to homespace. Do steps 1 and 2 first and keep the same Postgres version.
cd /opt/homespace
sudo docker compose down
sudo cp -a "$(sudo docker volume inspect -f '{{ .Mountpoint }}' homespace_db)/." /srv/homespace/db/
sudo cp -a "$(sudo docker volume inspect -f '{{ .Mountpoint }}' homespace_files)/." /srv/homespace/files/
sudo chown -R homespace:homespace /srv/homespace
sudo restorecon -R /srv/homespace # SELinux onlyThen do steps 3 and 4 and start again. Once everything works from the folders, the old volumes can go: docker volume ls lists them, and removing them deletes their data for good.