How to Install MariaDB on Docker Container (Step by Step)

When we want to install certain instances of MariaDB, MariaDB ColumnStore, or any other version of the software, there might be instances when no packages are available. Maybe we just want to isolate MariaDB from the rest of the system to make sure we don’t break anything. A virtual machine would undoubtedly serve the purpose. This, however, entails installing one system on top of another which necessitates a large number of resources.

In many cases, using containers is the best solution as it utilizes fewer resources while isolating the system. A container is designed to run a specific daemon as well as the software required for that daemon to function properly. Docker serves this purpose well.

Docker is a container management framework that necessitates a minimal amount of resources. It is capable of running on a virtualized system and is employed in both development and production environments.

install mariadb on docker container

Docker does not virtualize an entire system; instead, a container that contains only the packages that are not included in the underlying system. This allows developers to use docker for a variety of purposes, including renewing software and restoring data while keeping the main system isolated. In this article, we will be looking at how to install MariaDB on a Docker Container, how to run the container and kill the container process.

Benefits of MariaDB

MariaDB Benefits

MariaDB Server is one of the most popular open source relational databases. It is created by the original MySQL developers and is promised to remain open source. It is included in most cloud providers and is the default in most Linux versions.

The MariaDB database management system is a derivative of the MySQL database management system. The RDBMS is capable of processing data for both minor and large-scale activities.

MariaDB is a more advanced version of MySQL. It has a plethora of strong built-in capabilities as well as various usability, security, and performance enhancements that give substantial advantages over other SQL databases.

  • Compared to MySQL, MariaDB has 12 storage engines whereas MySQL has fewer.
  • MariaDB has a bigger connection pool that can accommodate up to 200,000+ connections, whereas MySQL has a smaller pool.
  • When comparing the performance of MariaDB vs MySQL, replication in MariaDB is quicker, but replication in MySQL is slower.
  • MariaDB does not allow Data Masking or Dynamic Columns, but MySQL does.
  • When comparing MariaDB with MySQL, MariaDB outperforms MySQL.

In general, MariaDB outperforms MySQL in terms of performance. MariaDB, in particular, has superior speed when it comes to views and managing flash storage via its RocksDB engine. When it comes to replication, MariaDB surpasses MySQL, making it a preferred DBMS over MySQL.

Installing Docker using a Universal Script

Install Mariadb docker container

Installing docker is as simple as running a single line command. The command below will install the Docker repositories, as well as the necessary kernel modules and packages, for the most common Linux distributions:

					curl -ssl | sh

To install Docker on Ubuntu or other OS, visit Docker’s official page here.

Running Docker

Some systems will require you to manually run Docker Daemon. The following commands will help you start docker on your system:

					sudo systemctl start docker
sudo gpasswd -a "${USER}" docker


If Docker is not running, most docker commands will fail and prompt the user with the following error:

Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

For more information on handling, Docker errors visit the official documentation page here.

Installing and Using MariaDB Using Docker Container

Now that we have Docker installed and running we can move on to installing MariaDB. The simplest approach to utilize MariaDB on Docker is to select a MariaDB image and launch a container.

Download MariaDB Docker Image

You may get a MariaDB image for Docker from the Official Docker MariaDB page, or you can pick another image that better matches your needs. You may use the following command to search Docker Hub (the official collection of repositories) for an image:

					docker search mariadb

Once you have found the image you want to use, you can download it via Docker. There might be some layers including dependencies that should be downloaded, Docker ensures downloads all necessary layers including dependencies that need to be downloaded.  You can run the command to install the default MariaDB image:

					docker pull mariadb

Additionally, to get a list of installed images on Docker you can you the command:

					docker images

Creating a MariaDB Container

An image is just software that needs to be launched. It is not a running software, thus to execute an image we must first construct a container. The official Docker documentation dives into details on how to set up containers owing to the user’s needs and can be found here. For this article to make a container for the official MariaDB image we can run the command:

					docker run --name mariadbh2s -e MYSQL_ROOT_PASSWORD=password -d mariadb

Flags for the above command:

  • –name mariadbh2s – To set the name of the container. If nothing is specified a random if will be automatically generated.
  • -e MYSQL_ROOT_PASSWORD=password – Setting root password to Mariadb.
  • -d is to run the container in the background.

Optionally if you want to run the MariaDB container and access the Database server from remote computers, you can use mapping and map the container’s MySQL port 3306 to host port 3306 port. For this, we will add the flag: -p host-port:container-port.

For example, we can run the above command with host port mapping:

					docker run --name mariadbh2s -p 3306:3306  -e MYSQL_ROOT_PASSWORD=password -d mariadb

We can also assign some host ports dynamically to the container, in case the default port of MariaDB is occupied on the host.

For that, the syntax will be like this: -p <container-port> or -p 3306. However, when you assign a dynamic port, to find out which port has been assigned and run:

					docker ps

As a result, you will get the active container details including the ports that have been mapped with the host.

Creating Docker Container

Starting and Stopping MariaDB Container

Docker allows easy manipulation of images. It allows us to restart a container with a single command:

					docker restart mariadbtest

The container can be stopped with the following command:

					docker stop mariadbtest

Running the above command will not destroy the contents of the container. The data is preserved in the container even if MariaDB is not running. To restart the container we can use the command:

					docker start mariadbtest

The container will be terminated gracefully when you use “docker stop”. A SIGTERM signal is sent to the mysqld process, and Docker will wait for the process to shut down before returning control to the shell. However, it is also possible to specify a timeout after which the process will be killed with a SIGKILL. Alternatively, the process can be terminated immediately with no timeout.

					docker stop --time=30 mariadbtest
docker kill mariadbtest


In case we want to destroy a container, because the container may not suit our needs, we can run the command:

					docker rm mariadbtest

Note that the command above does not destroy the data volume that Docker has created for /var/lib/mysql. If you want to destroy the volume as well, use:

					docker rm -v mariadbtest

MariaDB Container Setup - Complete

Congratulations you have successfully installed MariaDB on Docker. In this article we discussed in great depth the benefits of MariaDB and why is it the preferred DBMS over other SQL databases. Docker installation and running as well as errors, and discussed in great detail how to set up containers, install MariaDB on said containers, and run the containers.

Docker is an appealing containerization technology because it provides a dependable and scalable deployment environment for both production and non-production services. It makes use of the containerization concept to make procedures easy and scalable.

We hope this article helped you understand how Docker Containers and MariaDB can be used together in your next project. Check out our guide to install MariaDB cloud on your next Azure, GCP, or AWS project.

Avatar for Emad Bin Abid
Emad Bin Abid

I'm a software engineer who has a bright vision and a strong interest in designing and engineering software solutions. I readily understand that in today's agile world the development process has to be rapid, reusable, and scalable; hence it is extremely important to develop solutions that are well-designed and embody a well-thought-of architecture as the baseline. Apart from designing and developing business solutions, I'm a content writer who loves to document technical learnings and experiences so that peers in the same industry can also benefit from them.

0 0 votes
Article Rating
Notify of
Inline Feedbacks
View all comments
Would love your thoughts, please comment.x