Migrating docker volume from one server to another

Using docker run + tar (Manual Backup & Restore)**

  1. Stop the container (if running):
docker stop <container_name>
  1. Create a backup of the volume on the source host:
docker run --rm -v <volume_name>:/volume -v $(pwd):/backup busybox tar czf /backup/<backup_file>.tar.gz -C /volume ./

This creates a compressed .tar.gz file with all volume data.

  1. Transfer the backup file to the new host using scp, rsync, or any file transfer method
scp <backup_file>.tar.gz user@new_host:/path/to/backup/
  1. Restore the volume on the destination host:
docker volume create <new_volume_name>
docker run --rm -v <new_volume_name>:/volume -v $(pwd):/backup busybox sh -c "tar xzf /backup/<backup_file>.tar.gz -C /volume"

This extracts the backup into a new volume.

  1. Start your container with the new volume:
docker run -v <new_volume_name>:/path/in/container ...