Quick answer
What this guide helps you do
Build a recoverable Docker Compose backup covering definitions, secrets, bind mounts, named volumes and databases, then prove it with an isolated restore.
What a recovery set contains
A Compose service normally needs its Compose and override files, environment files and secrets, bind-mounted data, named volumes, consistent database exports, exact image references and written restore order. Images are often replaceable; unique data and secrets are not.
Inventory the project
sudo docker compose ls
cd /opt/containers/YOUR_PROJECT
sudo docker compose config --images
sudo docker compose config --volumes
sudo docker volume ls
sudo docker inspect YOUR_CONTAINER --format '{{json .Mounts}}'
Rendered configuration may contain secret values. Store it securely.
Make data consistent
Stop a simple file-based service during its copy. For databases, use the supported dump or backup method. Copying an actively changing database directory may produce an unusable recovery point even when every file copied.
Back up definitions and bind mounts
sudo rsync -aHAX --numeric-ids /opt/containers/YOUR_PROJECT/ /srv/backups/docker/YOUR_PROJECT/config/
sudo rsync -aHAX --numeric-ids /srv/appdata/YOUR_APP/ /srv/backups/docker/YOUR_PROJECT/appdata/
sudo chmod -R go-rwx /srv/backups/docker/YOUR_PROJECT
Keep a second copy off the Docker host and preferably off the same physical disk.
Back up a named volume
Identify the exact volume, stop or quiesce the application where needed, then use a temporary container:
sudo docker run --rm \
--mount source=YOUR_VOLUME,target=/source,readonly \
--mount type=bind,src=/srv/backups/docker/YOUR_PROJECT,dst=/backup \
alpine tar -czf /backup/YOUR_VOLUME.tar.gz -C /source .
Prove an isolated restore
Restore to a test host or separate project name. Recreate empty volumes, extract archives, restore databases using supported tools, change conflicting ports and start with docker compose up -d. Test login, existing records, uploads and a controlled write—not only the home page.
Verification checklist
- Every persistent mount is inventoried.
- Database consistency is handled.
- Secrets are protected.
- Backups leave the host or disk.
- Dates and checksums are recorded.
- Retention preserves earlier recovery points.
- An isolated restore completes.
- Expected application data is present.
Application-specific backup documentation takes priority over this framework.
Next: Fix Docker Containers After a Server Reboot. Start with How to Install Docker on Ubuntu Server.
Official reference: Back up, restore or migrate Docker volumes.