How to easily export and import docker volumes

Simple guide that shows you how to easily export and import docker volumes

5 months ago   •   2 min read

By Aquasp
Table of contents

If you’re like me, you prefer to run everything in Docker containers. They’re fast, isolated, and perfect for running multiple apps on one VPS.

But what happens when you want to:

  • Move a container to a new server?
  • Backup a database volume (NextCloud, PhotoPrism, Vaultwarden, etc.)?
  • Restore data after a crash?

Docker doesn’t include a built-in “export volume” button — but there’s a super simple and reliable trick using a temporary Ubuntu container.

Let’s go!

Step 1: List Your Volumes

docker volume ls

Example output:

DRIVER    VOLUME NAME
local     nextcloud_data
local     photoprism_storage
local     vaultwarden_data

Pick the one you want to export (e.g., nextcloud_data).

Step 2: Export a Volume → backup.tar.gz

Run this one-line command (replace nextcloud_data with your volume name):

docker run --rm -v nextcloud_data:/data -v "$(pwd)":/backup ubuntu \
  tar -czf /backup/nextcloud-data-backup.tar.gz -C /data ./

What this does:

  • Mounts your volume to /data inside a temporary container
  • Mounts your current folder to /backup
  • Creates a compressed archive of the entire volume

After it finishes, you’ll have a file like:
nextcloud-data-backup.tar.gz ← ready to download or move!

Pro tip: Add the date for clarity

docker run --rm -v nextcloud_data:/data -v "$(pwd)":/backup ubuntu \
  tar -czf "/backup/nextcloud-data-$(date +%Y-%m-%d).tar.gz" -C /data ./

Step 3: Import on the New Server

  1. Copy your backup.tar.gz file to the new server (via scp, rsync, etc.)

Then, create the empty volume (important!):

docker volume create nextcloud_data

Run the import command (from the folder containing the backup file):

docker run --rm -v nextcloud_data:/data -v "$(pwd)":/backup ubuntu \
  tar -xzf /backup/nextcloud-data-2025-04-05.tar.gz -C /data

Done! Your volume is now fully restored.

Never let Docker auto-create the volume during import — it can cause permission issues or merge problems.

Bonus: Using External Volumes with Docker Compose

If you're using docker-compose.yml, tell Docker that the volume is external (already exists):

services:
  nextcloud:
    image: nextcloud:latest
    volumes:
      - nextcloud_data:/var/www/html

volumes:
  nextcloud_data:
    external: true

Indentation matters — use exactly two spaces.

Real-World Use Cases

  • Migrating NextCloud to a new VPS
  • Backing up Vaultwarden before upgrading
  • Moving PhotoPrism library to a bigger server
  • Disaster recovery

This method is 100% reliable, works with any volume, and requires zero extra tools.

You now have a bulletproof Docker volume backup strategy.

If you enjoyed this quick tip, share it with a friend or subscribe to The Self Hosting Art.

Happy containerizing! 🐳

Thank you for reading!

Spread the word

Keep reading