How to backup data from docker-compose MariaDB container using mysqldump
For containers with a MYSQL_ROOT_PASSWORD stored in .env
This is the recommended best practice. For this example, we will assume that .env looks like this:
To create a dump:
To restore a dump from mariadb-dump.sql:
Note that you have to replace mariadb by the name of your container in docker-compose.yml.
For containers with a MYSQL_ROOT_PASSWORD set to some value not stored in .env
This is secure but you typically have to copy the password multiple times: One time for the mariadb container, one time for whatever container or application uses the database, and one time for any backup script that exports a SQL dump of the entire database
To create a dump:
To restore a dump from mariadb-dump.sql:
Replace YOUR_MARIADB_ROOT_PASSWORD by the password of your installation.
Furthermore, you have to replace mariadb by the name of your container in docker-compose.yml
For containers with MYSQL_ALLOW_EMPTY_PASSWORD=yes
This configuration is a security risk – see The security risk of running docker mariadb/mysql with MYSQL_ALLOW_EMPTY_PASSWORD=yes.
To create a dump:
To restore a dump from mariadb-dump.sql: