How to back up a MariaDB Docker container (2026)

The correct way to back up a MariaDB container is a logical dump, not a file copy. Run `mariadb-dump --all-databases --single-transaction --routines --triggers -uroot -p"$MARIADB_ROOT_PASSWORD"` inside the container and back up its output. Copying /var/lib/mysql while MariaDB is writing produces an inconsistent snapshot; --single-transaction wraps the dump in one InnoDB transaction, capturing every table at a single consistent point without a write lock.

Detection

What Dockstash detects

Env keys detectedMARIADB_ROOT_PASSWORD, MYSQL_ROOT_PASSWORD, MARIADB_DATABASE, MARIADB_USER
Default port3306
Live data paths (never copied live)/var/lib/mysql
Example imagesmariadb:11, mariadb:10.11, mariadb:10, mariadb
Commands

The dump command

mariadb-dump --all-databases --single-transaction --routines --triggers -uroot -p"$MARIADB_ROOT_PASSWORD"

The restore command

mariadb -uroot -p"$MARIADB_ROOT_PASSWORD"

--single-transaction wraps the dump in one InnoDB transaction, capturing every table at a single consistent point without a write lock.

The gotchas

Gotchas to avoid

  • Never restic the live /var/lib/mysql directory — a mid-write InnoDB copy is unrestorable.
  • Newer images ship mariadb-dump; older ones use mysqldump. Dockstash detects which binary the image provides.
  • MariaDB accepts either MARIADB_ROOT_PASSWORD or the legacy MYSQL_ROOT_PASSWORD env key, so both are detected.

Do it in one click with Dockstash

Dockstash runs the exact dump above, restics it off-site, and drill-tests the restore automatically — no script to maintain.

Start free All guides

Last updated: July 2026

Frequently asked questions

Is MariaDB backed up the same way as MySQL?

Almost identically. Both use --single-transaction for a consistent InnoDB snapshot. The difference is the client binary: recent MariaDB images ship mariadb-dump (mysqldump is a compatibility symlink). Dockstash picks the right one.

Which root password env key does Dockstash detect?

Both MARIADB_ROOT_PASSWORD and the older MYSQL_ROOT_PASSWORD are recognized, since MariaDB images accept either depending on version.

Can I restore a MariaDB dump into MySQL or vice versa?

Often, but not always — feature and syntax drift between the two can break edge cases. Restore into the same engine family the dump came from for a reliable result.

Why not just snapshot the volume?

The /var/lib/mysql volume is written continuously. A snapshot mid-write is inconsistent. A logical dump via mariadb-dump is the restorable path.