On this page
The right approach for Docker backups with restic
Docker data lives in three places. Bind mounts are host directories restic can read directly. Named volumes sit under /var/lib/docker/volumes/. Databases need a dump first, because copying live database files gives inconsistent snapshots.
Backing up bind mounts (simplest case)
Bind mounts such as ./data:/app/data are plain host paths, so back up the host path directly:
restic backup /opt/appdata /opt/compose /etc \
--tag docker \
--exclude="*/logs" \
--exclude="*/tmp"Running Home Assistant in a container? Our guide to backing up Home Assistant offsite with restic covers the config directory and the pre-backup snapshot.
Backing up named volumes
Named volumes live under /var/lib/docker/volumes/ and need root to read. Back up the whole directory and exclude build caches:
# List your volumes
docker volume ls
# Back up all named volumes
sudo restic backup /var/lib/docker/volumes/ \
--tag docker-volumes \
--exclude="*/buildkit"On Unraid, containers keep their data in appdata; backing up Unraid appdata with Restic covers the Unraid paths and scheduling.
Database pre-backup hook
For Postgres or MySQL, dump to a file before the restic run. A dump restores cleanly; live database files often do not.
#!/bin/bash
set -euo pipefail
source /etc/restic/env
# Dump Postgres
docker exec postgres pg_dumpall -U postgres > /tmp/pg_dump_$(date +%Y%m%d).sql
# Dump MySQL/MariaDB
docker exec mariadb mysqldump -u root -p"$MYSQL_ROOT_PASSWORD" --all-databases > /tmp/mysql_dump_$(date +%Y%m%d).sql
# Now back up everything including the dumps
restic backup /opt/appdata /tmp/pg_dump*.sql /tmp/mysql_dump*.sql \
--tag docker
# Clean up dumps
rm -f /tmp/pg_dump_*.sql /tmp/mysql_dump_*.sqlRun retention with your cleanup key from one trusted machine, never from the hosts you back up; see retention on ServerCrate vaults.
Full docker-compose setup
To run restic itself in a container, this compose snippet mounts your data read-only and runs a nightly backup:
services:
restic:
image: mazzolino/restic:latest
hostname: docker-host
restart: unless-stopped
environment:
RUN_ON_STARTUP: "true"
BACKUP_CRON: "0 30 2 * * *"
RESTIC_REPOSITORY: rest:https://vaultuser:YOUR_TOKEN@a1b2c3d4.vault.servercrate.net/
RESTIC_PASSWORD_FILE: /run/secrets/restic-pass
RESTIC_BACKUP_SOURCES: /data
volumes:
- /opt/appdata:/data:ro
- /root/.restic-pass:/run/secrets/restic-pass:roSetting up the vault target
Set your vault connection string as RESTIC_REPOSITORY. It is hosted Restic over HTTPS: no SSH or SFTP server, no egress fees.
Scheduling Docker backups automatically
For host-level backups, use a systemd timer; the systemd timer guide has the units. In a container, the mazzolino/restic image schedules with the BACKUP_CRON variable in standard cron syntax.
Dumps and backup must run in order: natural in a host script, and in a container use an entrypoint that dumps, then backs up.
What to skip in a Docker backup
Large, fast-changing, cheap-to-recreate artifacts do not belong in an offsite backup:
- /var/lib/docker/overlay2:Image layers, recreated by pulling. Can be hundreds of GB.
- Build caches:Buildkit caches in /var/lib/docker/buildkit.
- Log files:Exclude unless audit retention requires them.
- Temporary files:/tmp, /run and runtime state inside volumes.
Focus on what is painful to regenerate: database contents, uploaded files, config outside version control, and TLS certificates.
Verifying Docker volume restores
After a restore, confirm the app starts; for databases, load the dump into a test container and check row counts. See the restic restore guide.