Keenrig

Docker volumes explained: where app data lives

Named volumes, bind mounts and tmpfs: where Docker keeps your app data, how to find it, how to back it up safely, and the mistakes that lose data.

A container’s own filesystem is temporary. Remove the container — which every update does — and anything written inside it is gone. Volumes are how Docker keeps data across that. If you self-host, knowing where your volumes are is the difference between “update failed, restore from yesterday” and “update failed, start over”.

Three kinds of mounts

  • Named volumes: storage that Docker creates and manages. You refer to it by name (db-data); Docker decides where it lives on disk, normally under /var/lib/docker/volumes/<name>/_data.
  • Bind mounts: a directory or file on the host that you choose, mounted into the container (./data:/var/lib/app). You know exactly where it is, and so does every other tool on the host.
  • tmpfs mounts: in-memory only, gone when the container stops. Useful for caches and secrets that should never touch disk; useless for data you want to keep.
# named volume
docker run -d -v db-data:/var/lib/postgresql/data postgres:16

# bind mount
docker run -d -v /srv/app/data:/data example/app:1.4.2

Finding your data

docker volume ls
docker volume inspect db-data --format "{{ .Mountpoint }}"
docker inspect <container> --format "{{ json .Mounts }}"
sudo du -sh /var/lib/docker/volumes/*/_data

The last command is worth running now and then: a volume that quietly grew to fill the disk is one of the most common reasons a self-hosted server falls over.

Named volume or bind mount?

Named volumes are portable — the compose file does not depend on host paths — and Docker can pre-fill them with whatever the image ships at that path. Bind mounts are transparent: the data sits where you put it, which makes backups, inspection and moving to a new server simpler. The common trap with bind mounts is file ownership: the container may run as a user ID (say 1000 or 999) that cannot write to a directory created by root on the host.

Backing up a volume safely

Copying a volume is easy. Copying it in a state you can restore is the part people get wrong. A database writing to its files while you copy them can leave a backup that will not open.

  • For databases, use the database’s own dump tool (pg_dump, mysqldump, sqlite3 .backup) or stop the container briefly before copying.
  • For plain files (uploads, configs), a copy or archive of the directory is fine.
  • Back up the configuration that goes with the data: environment variables and keys. n8n, for example, encrypts stored credentials with a key it generates on first boot; data without that key is unreadable.
  • Keep at least one copy off the server, and test a restore on another machine.
# archive a named volume with a throwaway container
docker run --rm -v db-data:/src:ro -v "$PWD":/backup alpine \
  tar czf /backup/db-data-$(date +%F).tgz -C /src .

Mistakes that lose data

  • docker compose down -v: the -v removes named volumes too. Without it, volumes survive.
  • docker volume prune or docker system prune --volumes on a server where a stopped app’s volume counts as “unused”.
  • Mounting a volume at the wrong path: the app writes to a directory that is not mounted, so its data lives in the container layer and disappears with the next update. Check the image’s docs for the exact data path.
  • Renaming the compose project: named volumes are prefixed with the project name, so a new name means new, empty volumes.

Moving app data to a new server

Because volumes are just directories, moving an app between servers follows the same pattern every time:

  • Stop the app on the old server so nothing writes during the copy.
  • Copy the data directory, preserving ownership and permissions, for example with rsync -aHAX --numeric-ids over SSH.
  • Copy the configuration that goes with it: environment file, keys, compose file or settings.
  • Start the app on the new server with the same image version, check it, and only then point DNS at the new address.
sudo rsync -aHAX --numeric-ids /srv/app/data/ newserver:/srv/app/data/

--numeric-ids matters: the user IDs that own the files must stay the same numbers, because the process inside the container runs as a number, not a name. Keep the old server untouched for a few days in case something was missed.

How Keenrig stores app data

Keenrig deliberately uses bind mounts, not Docker named volumes. Each catalog manifest declares its volumes — for n8n it is one volume mounted at /home/node/.n8n — and Keenrig mounts each one from a directory under the app’s own folder on the server, by default /var/lib/keenrig/apps/<app-id>/volumes/<name>.

The reason is backups. Docker’s named volumes live outside Keenrig’s directory, so a backup that collects that directory would miss them. With bind mounts under one root, the backup command picks up every app’s data along with the server’s own database and keys. Keenrig also sets ownership on those directories so the app’s user inside the container can write to them.

curl -fsSL https://get.keenrig.com | sudo sh

Backups run as commands today: one to back up the whole server to a folder, a mounted NAS or your own S3 bucket, encrypted with a passphrase you choose, and one to restore — the whole server or only selected apps. The Backup page in the admin panel prints the exact commands.

Limits

  • Scheduled backups are still in progress; for now you run the command yourself or from your own timer.
  • If an app uses a separate managed database add-on, that database’s dump is not part of the backup command yet.
  • Bind-mounted data is only as safe as the disk it is on. A backup kept on the same server does not survive the server.