Restoring MariaDB Database Running inside Docker has not worked as expected – like – simple copying the externally mapped volume files and restarting the container.
Understand what Docker container is
You need to first understand what docker (or any other tech like it) contaienr is. It is sandboxed and isolated linux distribution. It runs with its own users, groups, software (described in the dockerfile). And finally – with files – changed during image run and files – mapped to external to the image volumes. The tricky moment is handling the externally mapped volume files.
Getting external files to work correctly
At first run – with empty volume – the mariadb database service creates system files. Some of these files are locked by the database for access and cannot be simply overwritten. You need to
- Have a second folder – mapped as volume – contaning the backup
- Start the docker container
- Stop the database service from command line – from withing the container
- Replace/Overwrite – the database files
- chown the files with the mysql user
- restart the service
I found the order of above steps were found after multiple attempts of:
- copying
- pasting
- restarting
- figuring out file ownership permissions
- and validating that the database data is up to date.
Hope this post helps. I’m developing some Micro Services https://programtom.com/dev/product-category/technologies/spring-boot-framework/?orderby=date-desc that use MariaDB database. It is crucial to create backups. It is crucial to have daily backup of the data – especially – when external users get into the software. Good Luck!