Migrating docker volume from one server to another
Using docker run
+ tar
(Manual Backup & Restore)**
- Stop the container (if running):
docker stop <container_name>
- 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.
- 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/
- 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.
- Start your container with the new volume:
docker run -v <new_volume_name>:/path/in/container ...