Skip to main content

How to Backup and Restore a Docker Volume

Purpose

Backup and restore Docker volumes easily for disaster recovery or migration between servers.


1. List Your Volumes

First, identify which volume you want to backup:

docker volume ls

2. Backup a Volume

Create a compressed backup (.tar.gz) of the volume:

docker run --rm \
  -v my-volume:/volume \
  -v $(pwd):/backup \
  alpine \
  tar czf /backup/my-volume-backup.tar.gz -C /volume .
  • my-volume: The name of the volume you are backing up.
  • $(pwd): Your current directory will store the backup file.

3. Restore a Volume

Restore the volume from a backup archive:

docker run --rm \
  -v my-volume:/volume \
  -v $(pwd):/backup \
  alpine \
  tar xzf /backup/my-volume-backup.tar.gz -C /volume

✅ Summary

  • Always test your backups after creating them.
  • Volumes can be moved between servers by copying the .tar.gz files.
  • Use alpine for lightweight backup/restore operations inside containers.

🛠️ Useful Commands

  • Inspect volume: docker volume inspect my-volume
  • Delete unused volumes: docker volume prune