I'm running around 15 containers on Ubuntu 22.04 with an ext4 filesystem, including services such as Jellyfin, Paperless, and Vaultwarden. I currently list the Docker volumes and copy their contents manually, but I'd like a daily automated backup instead. I'm considering volume-backup containers, Restic or Borg with the volumes mounted, or simply backing up the Compose files and data directories. Can this be done safely while everything is running, or should services be stopped to guarantee a consistent restore?
4 Answers
There isn’t one answer for every container. Ordinary files can often be copied while services are running, but databases may have files changing or being written halfway through the backup. For those, use the database’s native dump or backup command, briefly pause writes, or stop that specific service. A filesystem snapshot can help, but ext4 does not provide the same atomic snapshot workflow as ZFS or Btrfs without another storage layer.
The safest general-purpose approach is to record which containers are running, stop them briefly, archive each named volume, and then start the containers again. A small scheduled script can do this overnight. Mount each volume read-only into a temporary Alpine or similar container and create a compressed archive in your backup directory. Make sure the script only restarts containers that were running before the backup started.
That sounds simple enough for a nightly job. I’ll make sure the script handles failures so a partially completed backup doesn’t look valid.
If you can move the Docker data to ZFS or Btrfs, snapshots provide a nearly instant, point-in-time view that can be backed up without keeping containers stopped. You can then send snapshots to another system or storage target. On ext4, a file-based backup while containers are active is more like capturing whatever state each file happened to have at that moment, so it should not be treated as fully consistent for databases.
Keep your Compose files, environment templates, and backup configuration in version control, then back up the persistent data separately. You can use Restic, Borg, rsnapshot, or a dedicated Docker volume backup tool; the important parts are encryption, retention, an off-host copy, and regular restore tests. Backing up the entire Docker directory can work, but restoring it is more awkward because all containers and the Docker service generally need to be stopped first.

Even if the backup completes without errors, I’d still test restoring it. A backup that contains a database in an unusable state is not much help.