Installing MariaDB server on Raspberry Pi by Docker

2 minutes read


It is open-source relational database management system (RDBMS). The official image is not compatible to run with Raspberry Pi, So we have an alternative image by “jsurf/rpi-mariadb“. This is opensource version of MySQL, hence all the commands and functionality of MySQL can be used. Additionally, this server can be used for many application running on our Raspberry Pi.

Pull Image

Enter the following command to pull MariaDB docker Raspberry compatible image.

docker pull jsurf/rpi-mariadb

Now check that the image has been downloaded

docker images

Create Network

To begin using this database let us make a network and map it into this network. For more information refer the blog “Using Docker and command line cheat sheet“.

docker network create nextcloudDBMS

Run the MariaDB container

Running container for your specific application. I am going to use this for NextCloud application, therefore going to name it accordingly.

docker run --net=nextcloudDBMS\     #To connect with the created network.
--name sql-nextcloud\               #Giving name to the container.
-e MYSQL_ROOT_PASSWORD='November'\  #This will set the mariaDB root password.
-e MYSQL_DATABASE='Cloud-Database'\ #This will create a new database with the specified name.
-e MYSQL_USER='nextcloud'\          #This will create a mariaDB user with specified name. 
-e MYSQL_PASSWORD='Superman'\       #This is the password for above created user.
--restart always\                   #This will restart the container whenever it stops. Even on a restart.
-d jsurf/rpi-mariadb                #Run a detached container from the image of mariaDB 

Copy and paste the following command

docker run --net=nextcloudDBMS \
-e MYSQL_DATABASE='Cloud-Database' \
-e MYSQL_USER='nextcloud' \
-e MYSQL_PASSWORD='Superman' \
--restart always \
-d jsurf/rpi-mariadb

Additionally you can also create users or database in running database container. Follow the instructions below.

Enter into the container bash

docker exec -ti <container-ID> bash

Now start mysql as a root user

mysql -u root -p

Create User

Create your desires user and grant all the access by following command

GRANT ALL PRIVILEGES ON *.* TO '<username>'@'localhost' IDENTIFIED BY '<password>';

example :- GRANT ALL PRIVILEGES ON *.* TO 'NextCloud'@'localhost' IDENTIFIED BY 'Superman';

Create database

CREATE DATABASE <database-name>;

example:- CREATE DATABASE cloud_database;

List all users

SELECT User FROM mysql.user;

List all databases

show databases;

Therefore we have created a database server with virtual docker connection. Now we can install applications in other containers and make a connection to this container for storing data. 🙂

2 Replies to “Installing MariaDB server on Raspberry Pi by Docker”

  1. Great Article ! I’d like to convert the two 4-ft single linear T-12 fixtures in my kitchen to LED lights. These are 40W bulbs but I’ve measured 45+ watts probably due to inefficient ballasts.

  2. Good as an idea-likely unenforceable in reality, oh well..

Leave a Reply