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.
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./datanext tocompose.yaml. - Docker doesn’t back up volumes for you. Removing them with
docker compose down -vordocker volume prune -adeletes 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 or restic.
How to find the volumes to back up
<project>_<volume>. The db volume in the ~/wordpress project from the Docker Compose tutorial 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
2
Stop the app
stop keeps the containers and volumes. Don’t use down -v.3
Archive the volume
/data, writes a compressed archive to ~/backups, and is removed when tar finishes. Repeat for each volume.4
Start the app again
How to check the backup worked
tar lists the files inside, starting with ./.
How to restore a Docker volume
1
Stop the app
2
Create the volume if it doesn't exist
On a new server, create it with the exact name Compose expects: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
4
Start the app
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.- MariaDB / MySQL
- PostgreSQL
mysql image, use mysqldump, mysql and the MYSQL_* variables.-T turns off the pseudo-terminal so the output goes cleanly into the file. See also back up and restore MySQL databases.
How to back up all volumes every night
Save this as/usr/local/bin/backup-docker-volumes.sh:
sudo chmod +x /usr/local/bin/backup-docker-volumes.sh and add it to root’s crontab (sudo crontab -e):
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 ordata-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, 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.Why alpine and not ubuntu?
Any image withtar works; Docker’s own example uses ubuntu. alpine is a few megabytes, so it downloads fast.
Related guides
VPS and dedicated server guides
Every guide in this section.
Update Docker containers
Back up first, then update.
Encrypted backups with restic
Send your archives off the server.
Move Docker data to another disk
Change where Docker stores volumes.
Back up a Linux server
A full backup plan for the whole server.
Checked against the official Docker volumes documentation and the MariaDB container backup guide 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.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
- Discord: Join our Community
- Email: support@freakhosting.com
Last Updated: November 2026