How to Set Up MariaDB Docker Deployment?

Docker is used to develop, ship, and run applications. Docker allows you to isolate your applications from your infrastructure so that software can be delivered quickly and efficiently.

To learn more about Docker, check this out:

Today, we will see how to set up MariaDB Deployment using a MariaDB docker image.

Installation Guide:

The following are the steps involved in setting up MariaDB Docker Deployment:

Step 1: Install Docker using Universal Installation Script

The first task is to install necessary Docker repositories including packaging and Kernal modules on your Linux system. This can be achieved by running the following script:

curl -sSL | sh

Step 2: Start the Docker Daemon

After running the script, we will start the Docker Daemon.

sudo systemctl start docker

sudo gpasswd -a "${USER}" docker

Step 3: Use MariaDB Docker Image

Let’s now deploy MariaDB using a MariaDB Docker image. With the help of this image, we will create a container. To do that, follow the commands mentioned below:

Use the following command to search for MariaDB Docker images:

docker search mariadb

Once you have decided which MariaDB image to download, use the following command to install the image:

docker pull mariadb:10.x

Run the following command to see the list of all the Docker images installed on your system:

docker images

To run the MariaDB image we just installed, we need a container. In this step, we will create a container to run the image.

docker run --name mariadbprac -e MYSQL_ROOT_PASSWORD=password123 -p 3308:3308 -d

The name that we have given to the container is mariadbprac.

docker run --name mariadbprac -e MYSQL_ROOT_PASSWORD=password123 -p 3308:3308 -d

Issue the following command to see all the containers on your system:

docker ps

How to Run and Stop the Container?

Use the following command to stop a running container:

docker stop mariadbprac

This will instantly stop the container.

Now, if you want to start the container, issue the following command:

docker restart mariadbprac

This will start your container.

How to Access the Container?

Bash can be used to access the container like this:

docker exec -it mariadb_prac_test bash

How to Connect MariaDB from Outside of Container?

We can connect to MariaDB server using TCP. For that, the Client should be running on the same machine as the server container.

But before that, we need to find the IP address of the assigned container. To do that, we will use the following command syntax:

Docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' mariadprac

We have found the IP address. Execute the following command to force the TCP connection:

mysql -h -u root -p

Sometimes, it is required to also mention the port for the server to force the TCP connection like this:

mysql -h -P 3308 --protocol=TCP -u root -p

Now, we have successfully set up MariaDB docker deployment.


In today’s guide, we explored in detail the installation process of Docker using Universal Installation Script. Then, we saw how to start the Docker Deamon. We also learned how to create a container to run a MariaDB image. In the end, we explored how we can connect to MariaDB from outside the container.

About the author

Karim Buzdar

Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. He blogs at LinuxWays.