Docker Backup Strategy: How to Protect Volumes, Databases, and Compose Files
BackupsDocker VolumesDisaster RecoveryDatabasesReliability

Docker Backup Strategy: How to Protect Volumes, Databases, and Compose Files

SSelfHosting.cloud Editorial Team
2026-11-27
7 min read

A practical Docker backup strategy for protecting volumes, databases, Compose files, secrets, and the restore process.

A dependable Docker backup strategy protects more than containers: it preserves application data, database state, configuration, secrets, and the instructions needed to rebuild the server. This checklist explains what to back up, how to handle databases and volumes, how to keep an off-site copy, and how to prove that restoration works before an outage makes the decision for you.

Overview

Docker containers are usually disposable. If an image or container is lost, you can normally pull the image again and recreate it from a Compose file. The difficult-to-replace material lives elsewhere: named volumes, bind-mounted directories, database records, uploaded files, encryption keys, and the configuration that connects everything.

A useful self-hosted server backup has four layers:

  • Rebuild data: Compose files, environment-variable templates, image references, reverse-proxy configuration, scripts, and deployment notes.
  • Application data: Docker volumes and bind mounts containing uploads, documents, media, indexes, and application state.
  • Database exports: Logical dumps created with the database's own tools, rather than relying only on a live copy of database files.
  • Recovery metadata: Encryption keys, recovery codes, access details, DNS notes, and the order in which services must be restored.

The goal is not to copy every byte on every run. The goal is to meet a defined recovery point objective (how much recent data you can afford to lose) and recovery time objective (how long the service can remain unavailable). A small home server may accept a daily backup and manual restoration. A business-critical service may need more frequent exports, multiple destinations, and a documented recovery procedure.

Start with an inventory. For each Compose project, record its project directory, services, image versions, ports, volumes, bind mounts, databases, secrets, and dependencies. A simple table or version-controlled repository is sufficient. Keep secrets out of public repositories, but do not leave the only copy of a secret inside an inaccessible container or on the server being backed up.

Checklist by scenario

For every Docker Compose project

  • Save compose.yml and any override files.
  • Save the environment-variable names and safe, non-secret defaults in an .env.example file.
  • Record image tags or digests, networks, published ports, health checks, and restart policies.
  • Document every named volume and bind mount, including its purpose and approximate size.
  • Back up custom configuration files, scripts, certificates, and reverse-proxy rules.
  • Record the external dependencies: DNS provider, object storage, SMTP relay, OAuth provider, or tunnel configuration.

Configuration is often small enough to store in encrypted version control. Data should normally go through a backup system that supports retention, encryption, integrity checks, and a separate destination.

For named volumes and bind mounts

First identify the actual storage locations with docker volume ls and docker inspect. Do not assume that a volume contains all application data; many images use a bind mount for uploads and a separate volume for a database.

For relatively static files, a stopped-container archive can be practical:

docker compose stop app

docker run --rm \
  -v project_uploads:/source:ro \
  -v "$PWD/backups":/dest \
  alpine tar czf /dest/uploads-$(date +%F).tar.gz -C /source .

docker compose start app

Adapt the volume name and destination to your project. Stopping a service reduces the chance of copying a partially written file, but it does not create a consistent database backup. For large or frequently changing data, use the application's export or snapshot method and verify that the backup job can handle permissions, symbolic links, and extended attributes where those matter.

For PostgreSQL

Create a logical dump from the running database with the client version supported by your environment. A common pattern is:

docker compose exec -T postgres \
  pg_dump -U "$POSTGRES_USER" "$POSTGRES_DB" \
  | gzip > backups/postgres-$(date +%F-%H%M).sql.gz

Test the command with your actual service name and authentication settings. For several databases or roles, use a broader export strategy, and preserve any required extensions. A database volume copy can support some recovery designs, but it should complement—not replace—a tested logical dump unless you have deliberately designed and tested physical backups.

For other databases, use their native dump tools and follow their consistency guidance. Stopping a web container does not necessarily make a database file copy safe if the database service remains active.

For an off-site and encrypted copy

Use at least one backup destination that is not mounted permanently with write access from the Docker host. A second disk protects against some local failures; an off-site destination addresses risks such as theft, hardware loss, and local damage. Keep credentials for the backup destination separate from the host's normal administrative credentials.

Encrypt backups before they leave the server when the storage provider or transport does not already provide the protection you require. Store the decryption key in a separate, accessible location and document how an authorized person can retrieve it. Encryption without key recovery is equivalent to data loss during a disaster.

A practical retention example is several recent daily copies, a smaller set of weekly copies, and a few monthly copies. Choose the actual numbers based on storage capacity, data-change rate, and recovery requirements. Apply automatic expiration only after confirming that the retention job cannot delete the sole usable copy.

For a complete server rebuild

Keep a recovery note outside the server. It should list the operating-system setup, firewall rules, Docker installation steps, DNS records, proxy configuration, secret locations, backup restoration commands, and service startup order. Include application-specific notes for systems such as Nextcloud, Paperless-ngx, Authentik, or a self-hosted password manager. Relevant deployment and maintenance details can be reviewed in the Nextcloud Docker guide, Paperless-ngx guide, and Authentik recovery guide.

What to double-check

  • Completeness: Compare the inventory with the backup contents. Check uploads, database dumps, Compose files, certificates, and application-specific keys.
  • Consistency: Confirm that database dumps finish successfully and are not zero-byte or truncated files. Review exit codes and logs, not just whether a scheduled task ran.
  • Permissions: Restore into a test directory or temporary host and confirm that the container's user can read and write restored files.
  • Compatibility: Record image and database versions. A restore may require starting with the same major version before performing a planned upgrade.
  • Secrets: Verify that encryption keys, signing keys, salts, and recovery codes are available. Do not assume they can be regenerated without consequences.
  • Off-site access: Confirm that the destination can be reached using a fresh credential or recovery method, especially after changing the original server.
  • Restore order: Restore secrets and networks, then databases, application files, and dependent services. Bring up one project at a time and inspect logs.

At least periodically, perform a complete restore on a temporary host or isolated network. Pull the required images, recreate the project from the saved files, import a database dump, restore volumes, and verify a real user workflow. For example, open a document, log in through the identity provider, upload a file, or send a test message. A backup that cannot produce a working service is only an archive.

Common mistakes

  • Backing up containers instead of data: Container layers are replaceable and may not contain persistent state.
  • Copying only the Docker volume: Compose files, environment variables, external configuration, and secrets are also required for reconstruction.
  • Taking a live database file copy: Active database files may be internally inconsistent. Prefer native logical dumps or a database-aware physical backup method.
  • Keeping every copy on the same host: A failed disk, ransomware event, or accidental deletion can remove the original and its backup together.
  • Encrypting without a recovery plan: Test key retrieval and keep a protected copy of the key outside the backup set.
  • Never testing restoration: Successful upload does not prove that an archive can be read, decrypted, imported, and used.
  • Updating images without rollback information: Keep the previous image reference and make sure backups are taken before significant upgrades. The Renovate for Docker Compose guide covers a review-based update workflow.

When to revisit

Review this Docker backup strategy before seasonal planning cycles, after adding a new Compose project, and whenever a service changes its storage layout or database. Revisit it after moving from a home server to a VPS, changing backup providers, rotating encryption keys, or adopting object storage such as MinIO. The MinIO storage and recovery guide is useful when object storage becomes part of the design.

Schedule a lightweight check each backup cycle: inspect job status, destination capacity, and recent file timestamps. Perform a sample file restore regularly, and perform a complete service restore at an interval appropriate to the system's importance. Update the recovery note whenever commands, image versions, credentials, or dependencies change.

Action plan: inventory every project today; save Compose files and recovery metadata; create database-native exports; send an encrypted copy off-site; then schedule a restore test and record the result. Repeat the checklist whenever your self-hosted server gains a new application or its recovery assumptions change.

Related Topics

#Backups#Docker Volumes#Disaster Recovery#Databases#Reliability
S

SelfHosting.cloud Editorial Team

Infrastructure and Self-Hosting Editors

Senior editor and content strategist. Writing about technology, design, and the future of digital media. Follow along for deep dives into the industry's moving parts.