Docker How To Backup Volume
Docker volumes are all stored within a directory on the host. Each volume is stored within it’s own subdirectory. You can backup that directory or any specific subdirectory that you choose.
Volumes are kept here by default:
/var/lib/docker/volumes
Backup all volumes:
tar cvfz backup.tar.gz -C /var/lib/docker/volumes .
Restore all volumes:
tar xvfz backup.tar.gz -C /var/lib/docker/volumes
Backup a specific volume:
tar cvfz backup.tar.gz -C /var/lib/docker/volumes/my_volume1 .
Restore a specific volume:
tar xvfz backup.tar.gz -C /var/lib/docker/volumes/my_volume1
Alternative - backup using a temporary container
You can also backup a volume using a temporary container, like this:
docker run --rm -v my_volume1:/data -v /backup:/backup ubuntu tar czvf /backup/backup.tar.gz -C /data .
restore with a temp container like this:
docker run --rm -v my_volume2:/data -v /backup:/backup ubuntu tar xzvf /backup/backup.tar.gz -C /data