What is the best way to use mariadb with persistent storage? I want to use a custom location on disk as persistent usage and a custom my.cnf file with the parameter
Just follow the instructions on Dockerhub in the sections “Using a custom MySQL configuration file” and “Where to Store Data”. The example
docker run --name some-mariadb -v /my/own/datadir:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mariadb:tag
mounts the local folder
my/own/datadir into the database container. You don’t have to change
my.cnf for this.
podman run --security-opt label=disable --rm -v $HOME/mysql-data:/var/lib/mysql/data:z -e MYSQL_USER=user -e MYSQL_PASSWORD=pass -e MYSQL_DATABASE=db -p 3306:3306 mariadb/server
No reason to disable SELinux here. And you figured out the solution. Anything in your homedir is owned by “root” in your container. So if you want the database to be owned by the mariadb user, then you need to chown it to match the correct user.