> ## Documentation Index
> Fetch the complete documentation index at: https://help.freakhosting.com/llms.txt
> Use this file to discover all available pages before exploring further.

# How to Back Up and Restore Docker Volumes

> Back up Docker volumes by stopping the app and archiving each volume with a temporary container and tar. Restore the archive the same way. Database dumps included.

To back up a Docker volume, stop the app with `docker compose stop`, then run a temporary container that mounts the volume and your backup folder and archives it: `docker run --rm -v app_data:/data:ro -v ~/backups:/backup alpine:3.24 tar czf /backup/app_data.tar.gz -C /data .`. Restore by extracting the archive into a volume the same way. Dump databases with their own tools as well.

| Difficulty | Time | Works on | Needs |
| - | - | - | - |
| Beginner | 15 minutes | Any Linux server with Docker | Docker access, free disk space for the archives |

## Before you start

* A **volume** is storage that Docker manages for a container. Named volumes live under `/var/lib/docker/volumes/<name>/_data`. A **bind mount** is a normal folder on the server, such as `./data` next to `compose.yaml`.
* Docker doesn't back up volumes for you. Removing them with `docker compose down -v` or `docker volume prune -a` deletes the data for good.
* Copying a database's files while it is running can give you a broken copy. Stop the app first, or dump the database with its own tool.
* A backup on the same disk doesn't survive a disk failure or a rebuild. Copy the archives off the server, for example with [rclone](https://help.freakhosting.com/portals/other/how-to-back-up-to-cloud-storage-with-rclone.md) or [restic](https://help.freakhosting.com/portals/other/how-to-make-encrypted-backups-with-restic.md).

## How to find the volumes to back up

```bash theme={null}
docker volume ls
docker inspect wordpress-db-1 --format '{{ json .Mounts }}'
```

Compose names volumes `<project>_<volume>`. The `db` volume in the `~/wordpress` project from the [Docker Compose tutorial](https://help.freakhosting.com/portals/other/how-to-use-docker-compose.md) is called `wordpress_db`. `"Type":"bind"` entries in the `inspect` output are folders; back those up as normal files.

## How to back up a Docker volume

**1. Make a backup folder**

```bash theme={null}
mkdir -p ~/backups
```

**2. Stop the app**

```bash theme={null}
cd ~/wordpress
docker compose stop
```

`stop` keeps the containers and volumes. Don't use `down -v`.

**3. Archive the volume**

```bash theme={null}
docker run --rm -v wordpress_db:/data:ro -v ~/backups:/backup alpine:3.24 \
  tar czf /backup/wordpress_db-2026-11-04.tar.gz -C /data .
```

The temporary container mounts the volume read-only at `/data`, writes a compressed archive to `~/backups`, and is removed when `tar` finishes. Repeat for each volume.

**4. Start the app again**

```bash theme={null}
docker compose start
```

## How to check the backup worked

```bash theme={null}
ls -lh ~/backups
tar tzf ~/backups/wordpress_db-2026-11-04.tar.gz | head
```

You see the archive with a sensible size, and `tar` lists the files inside, starting with `./`.

## How to restore a Docker volume

**1. Stop the app**

```bash theme={null}
cd ~/wordpress
docker compose stop
```

**2. Create the volume if it doesn't exist**

On a new server, create it with the exact name Compose expects:

```bash theme={null}
docker volume create wordpress_db
```

Compose prints a warning that the volume already exists but wasn't created by Compose. It still uses it.

**3. Extract the archive into the volume**

```bash theme={null}
docker run --rm -v wordpress_db:/data -v ~/backups:/backup:ro alpine:3.24 \
  tar xzf /backup/wordpress_db-2026-11-04.tar.gz -C /data
```

**4. Start the app**

```bash theme={null}
docker compose up -d
```

> [!WARNING]
>
> Restoring into a volume that already has data mixes old and new files. To restore cleanly, remove the volume first with `docker volume rm wordpress_db` (after checking your archive is good), create it again and then extract.

## How to back up a database without stopping it

Dump files from the database's own tool are consistent while the app keeps running, and they restore across versions more reliably than raw files.

> [tab] MariaDB / MySQL
>
> ```bash theme={null}
> cd ~/wordpress
> docker compose exec -T db sh -c 'mariadb-dump -u"$MARIADB_USER" -p"$MARIADB_PASSWORD" "$MARIADB_DATABASE"' > ~/backups/wordpress-2026-11-04.sql
> ```
>
> Restore with:
>
> ```bash theme={null}
> docker compose exec -T db sh -c 'mariadb -u"$MARIADB_USER" -p"$MARIADB_PASSWORD" "$MARIADB_DATABASE"' < ~/backups/wordpress-2026-11-04.sql
> ```
>
> The variables come from the container's own environment. With the `mysql` image, use `mysqldump`, `mysql` and the `MYSQL_*` variables.

> [tab] PostgreSQL
>
> ```bash theme={null}
> cd ~/myapp
> docker compose exec -T db pg_dump -U postgres -d myapp > ~/backups/myapp-2026-11-04.sql
> ```
>
> Restore into an empty database with:
>
> ```bash theme={null}
> docker compose exec -T db psql -U postgres -d myapp < ~/backups/myapp-2026-11-04.sql
> ```

`-T` turns off the pseudo-terminal so the output goes cleanly into the file. See also [back up and restore MySQL databases](https://help.freakhosting.com/portals/other/how-to-back-up-and-restore-mysql-databases.md).

## How to back up all volumes every night

Save this as `/usr/local/bin/backup-docker-volumes.sh`:

```bash theme={null}
#!/bin/bash
set -euo pipefail
BACKUP_DIR=/root/backups
DATE=$(date +%F)
mkdir -p "$BACKUP_DIR"
for VOL in $(docker volume ls -q); do
  docker run --rm -v "$VOL":/data:ro -v "$BACKUP_DIR":/backup alpine:3.24 \
    tar czf "/backup/${VOL}-${DATE}.tar.gz" -C /data .
done
find "$BACKUP_DIR" -name '*.tar.gz' -mtime +7 -delete
```

Make it executable with `sudo chmod +x /usr/local/bin/backup-docker-volumes.sh` and add it to root's crontab (`sudo crontab -e`):

```bash theme={null}
15 3 * * * /usr/local/bin/backup-docker-volumes.sh
```

This archives every volume at 03:15 and keeps seven days. It doesn't stop the apps, so pair it with database dumps for anything that runs a database. See [schedule tasks with cron](https://help.freakhosting.com/portals/other/how-to-schedule-tasks-with-cron.md).

## Frequently asked questions

### Can I just copy /var/lib/docker/volumes?

You can, as root and with the containers stopped, but the helper container method works whichever disk or `data-root` Docker uses and gives you one archive per volume. Never copy the whole `/var/lib/docker` while Docker is running.

### How do I move volumes to another server?

Back up each volume, copy the archives and your project folders (with `.env`) to the new server with [rsync or scp](https://help.freakhosting.com/portals/other/how-to-copy-files-with-scp-and-rsync.md), create the volumes there and restore them, then run `docker compose up -d`.

### Does a VPS backup include my Docker volumes?

A whole-server backup or snapshot includes everything on the disk, Docker data too. Still keep app-level backups, because they let you restore one app without rolling back the whole server. See [schedule and restore backups](https://help.freakhosting.com/portals/vps-panel/how-to-schedule-and-restore-backups.md).

### Why alpine and not ubuntu?

Any image with `tar` works; Docker's own example uses `ubuntu`. `alpine` is a few megabytes, so it downloads fast.

## Related guides

> [card] [VPS and dedicated server guides](https://help.freakhosting.com/portals/other/vps-and-dedicated-server-guides.md)
>
> Every guide in this section.

> [card] [Update Docker containers](https://help.freakhosting.com/portals/other/how-to-update-docker-containers.md)
>
> Back up first, then update.

> [card] [Encrypted backups with restic](https://help.freakhosting.com/portals/other/how-to-make-encrypted-backups-with-restic.md)
>
> Send your archives off the server.

> [card] [Move Docker data to another disk](https://help.freakhosting.com/portals/other/how-to-move-docker-data-to-another-disk.md)
>
> Change where Docker stores volumes.

> [card] [Back up a Linux server](https://help.freakhosting.com/portals/other/how-to-back-up-a-linux-server.md)
>
> A full backup plan for the whole server.

***

> [!NOTE]
>
> **Checked against the official [Docker volumes documentation](https://docs.docker.com/engine/storage/volumes/#back-up-restore-or-migrate-data-volumes) and the [MariaDB container backup guide](https://mariadb.com/docs/server/server-management/automated-mariadb-deployment-and-administration/docker-and-mariadb/container-backup-and-restoration)** on 4 November 2026; volume backup, restore and listing commands tested on Ubuntu 24.04 LTS with Docker Engine 29.9.2 (using a local BusyBox image in place of `alpine`). Commands can differ on other releases.

> [!NOTE]
>
> ### Need Extra Help?
>
> If you encounter any issues, our support team is ready to assist:
>
> * **Live Chat:** Quick assistance via our website.
> * **Support Ticket:** [Open a Ticket](https://freakhosting.com/clientarea/submitticket.php)
> * **Discord:** [Join our Community](https://discord.gg/freakhosting)
> * **Email:** [support@freakhosting.com](mailto:support@freakhosting.com)

> [!TIP]
>
> ### Save on Your Hosting
>
> Ready to upgrade your hosting? Use code **KB20** at checkout for **20% off** your first order!

***

**Last Updated:** November 2026


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.