↑ ↓ select, Enter open, Esc close

Back up a Docker volume to a tar archive

Caution: This command changes the system. Understand what it does before you run it.

Adjust the values, the command updates live
root@server
docker run --rm -v app_data:/data:ro -v /root/docker-backup:/backup alpine tar czf /backup/app_data.tar.gz -C /data .

Starts a short-lived Alpine container that mounts the volume read-only under /data and the host target directory under /backup, and packs the contents with tar. The helper container is removed automatically afterwards. The volume name is listed in docker volume ls, with Compose usually prefixed by the project name.

Note: For a consistent backup of databases, stop the associated container first or, better, create a dump. An archive with the same name in the target is overwritten, and on the first run the alpine image is downloaded.

Also searched as

  • how to backup docker volume
  • docker volume to tar.gz
  • export docker volume data

Related one-liners

All in Docker

Read first, then run.

The commands on myline.de act directly on servers, files and databases. A wrong path or placeholder can delete data irreversibly or make a server unreachable.

  • All commands are provided without warranty and are not tested on every system.
  • Understand what a command does before running it, and check every placeholder.
  • Make a backup first and, if possible, try it on a test system.
  • You run commands at your own risk. Liability for damages is excluded to the extent permitted by law.