Try MariaDB Server 10.3 in Docker
There are times when you may want to test specific software or a specific version of software. In my case, I wanted to play with MariaDB Server 10.3.6 Release Candidate and some of the new, upcoming features. I didn’t want to have a permanent installation of it on my laptop so I chose to put it in a Docker container that I can easily copy to another place or remove. These are the steps I had to take to get it done.
I won’t go through how to install Docker itself. There is good documentation for it, which can be found here: https://docs.docker.com/install/
After the installation is completed, make sure Docker is up and running by opening a terminal and typing in a terminal window:
There are a lot of other alternatives to see that Docker is up and running, but “info” provides useful information about your Docker environment.
After Docker is set up, it’s time to create a container running MariaDB Server. The easy way to do it is to use the MariaDB Dockerfiles available on Docker Hub. These images are updated fairly quickly when a new release is made of MariaDB. It’s this easy to get MariaDB Server 10.3 RC up and running by using the Dockerfile:
docker pull mariadb:10.3 docker run --name mariadbtest -e MYSQL_ROOT_PASSWORD=mypass -d mariadb:10.3
Check that MariaDB started correctly by looking at the logs:
docker logs mariadbtest
The last row in the log will also tell you what version of MariaDB is running.
For documentation on this, refer to Installing and using MariaDB via Docker in the MariaDB documentation.
In my case, I wanted to test out the latest version of MariaDB that wasn’t yet at the time of writing available in the Dockerfile on Docker Hub. I will next go through the steps to create and populate a container without using a Dockerfile.
To get going we’ll need a new container. We need the container to be based on a operating system that is supported for MariaDB. I’ll base it off Ubuntu Xenial (16.04).
docker run -i -t ubuntu:xenial /bin/bash
When running that command, Docker will download the Ubuntu Xenial Docker image and use it as the base for the container. The /bin/bash at the end will take us into the shell of the container.
Inside the container I want to install MariaDB 10.3. I used the repository configuration tool for MariaDB to get the right configuration to add to the clean Xenial installation I now have. The tool gave me the following three commands to run.
add-apt-repository 'deb [arch=amd64,i386,ppc64el] http://mirror.netinch.com/pub/mariadb/repo/10.3/ubuntu xenial main' apt update apt install mariadb-server
The last command will start installing MariaDB, which will ask for a root password for MariaDB to be defined. Once that is done and the installation finishes we can exit from the container and save the configuration that we’ve done. The container id, which is needed as an argument for the commit command is easily fetched from the shell prompt , root@[container id].
exit docker commit [container id] rasmus/mariadb103
It’s pretty useful to be able to have the database data stored outside the container. This is easily done by first defining a place for the data on the host machine. In my case, I chose to put it in /dbdata in my home directory. We want to expose it as the /data directory inside the container. We start the container with this command.
docker run -v="$HOME/dbdata":"/data" -i -t -p 3306 rasmus/mariadb103 /bin/bash
Inside the container, let’s start the MariaDB server and run the normal installation and configuration scripts.
/usr/bin/mysqld_safe & mysql_install_db mysql_secure_installation
After this we can test connecting to MariaDB 10.3 and hopefully everything works.
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 16
Server version: 10.3.6-MariaDB-1:10.3.6+maria~xenial-log mariadb.org binary distribution
Now I want to save the configuration so far to easily be able to start from state whenever needed. First, I exit the MariaDB monitor and then shutdown MariaDB.
exit mysqladmin -p shutdown
Then another exit will get us out of the container and then we can save the new version of the container by running the below docker commit command in the host terminal. Again, take the container id from the shell prompt of the container.
exit docker commit -m "mariadb 10.3.6" -author="Rasmus" [container id] rasmus/mariadb103:"basic configuration"
Tadaa, done! MariaDB 10.3.6 is now available in a Docker container and I can start playing with the cool new features of MariaDB Server 10.3 like System Versioned Tables. To start the container, I just run:
docker run -v="$HOME/dbdata":"/data" -i -t -p 3306 rasmus/mariadb103:”basic configuration” /bin/bash