---
title: 'How to install MariaDB in Docker | Zomro'
description: 'In this article, we will look at how to install the MariaDB MySQL server in a Docker container, and see how to connect it to phpMyAdmin in the docker-compose'
image: 'https://dx86q6oq7ry0e.cloudfront.net/uploads/media/blog/a48@server-panel.net/2022/11/01/1669736570_1.png'
---

![opened image]()

  * [Zomro](https://zomro.com/)
  * [FAQ](https://zomro.com/blog/faq/)
  * How to install MariaDB in Docker 



# How to install MariaDB in Docker

20-11-2022

In this article, we will look at how to install the MariaDB MySQL server in a Docker container and see how to connect it to phpMyAdmin in the docker-compose that we installed in the article [ **How to install phpMyAdmin in Docker**.](https://zomro.com/rus/blog/faq/289-kak-ustanovit-phpmyadmin-v-docker)  


**So, let's install Docker.**

As usual, we update the OS packages.   

    
    
    apt update

  
We will install the necessary packages and add a new repository:
    
    
    apt install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
    
    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
    
    add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

  
We update the packages with the new repository:
    
    
    apt update

  
We install Docker.
    
    
    apt-get install docker-ce docker-ce-cli containerd.io

  
We check the Docker version:
    
    
    docker --version

  
![How to install MariaDB in Docker - 1](https://dx86q6oq7ry0e.cloudfront.net/uploads/media/blog/a48@server-panel.net/2022/11/01/1669736570_1.png)We check the status:
    
    
    systemctl status docker

  
![How to install MariaDB in Docker - 2](https://dx86q6oq7ry0e.cloudfront.net/uploads/media/blog/a48@server-panel.net/2022/11/01/1669736593_2.png)  
If it did not start, we start it:
    
    
    systemctl start docker
    

  
And add it to autostart.
    
    
    systemctl enable docker
    

  
![How to install MariaDB in Docker - 3](https://dx86q6oq7ry0e.cloudfront.net/uploads/media/blog/a48@server-panel.net/2022/11/01/1669736594_4.png)

**Installing Docker-Compose**
    
    
    curl -L "https://github.com/docker/compose/releases/download/1.25.5/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
    

  
We set execution permissions for the **docker-compose** file. 
    
    
    chmod +x /usr/local/bin/docker-compose
    

  
We check if Docker-Compose is installed:
    
    
    docker-compose --version
    

  
![How to install MariaDB in Docker - 4](https://dx86q6oq7ry0e.cloudfront.net/uploads/media/blog/a48@server-panel.net/2022/11/01/1669740139_5.png)  
As we can see, everything is fine. Let's create a file for Docker-Compose.  
  
To orient ourselves in the future about where and what we have installed, we will create a separate folder for this project in the **/home** directory and navigate to it.
    
    
    mkdir /home/mariadb && cd /home/mariadb

  
In this guide, we will install a specific version of MariaDB 10.8. But you can install the one you need from those available on the hub.docker.com website.  
  
To create the **docker-compose.yaml** file, we will use the repository at the link <https://hub.docker.com/_/mariadb>  
  
We create the **docker-compose.yaml** or **docker-compose.yml** file:
    
    
    vim docker-compose.yaml
    

  
And add the following code to it:
    
    
    version: '3.1'
    
    services:
      mariadb:
        container_name: mariadb
        image: mariadb:10.8
        ports:
            - 3310:3306
        environment:
            MARIADB_USER: admin
            MARIADB_PASSWORD: your_password
            MARIADB_ROOT_PASSWORD: your_strong_pass
        restart: always

  
![How to install MariaDB in Docker - 5](https://dx86q6oq7ry0e.cloudfront.net/uploads/media/blog/a48@server-panel.net/2022/11/01/1669749511_10.png)  
Where:  
  
**mariadb** : the name of your container;  
**image: mariadb:10.8** : the image from which mariadb will be deployed;  
**ports: 3310:3306** \- port 3310 that we will use to connect to mariadb;  
**restart:always** \- indicates that the container will be restarted in case of failure or server reboot;  
**MARIADB_USER** : creating a new user, in this case, it is admin;  
**MARIADB_PASSWORD** : the password for the admin user;  
**MARIADB_ROOT_PASSWORD** : this password will be set for the root superuser account of MariaDB.  
  
We run our script (for this you need to be in the directory where our file was created. In this case, it is **/home/mariadb**):
    
    
    docker-compose up -d 
    

  
We wait for the images to download and deploy.  
  
We check:
    
    
    docker-compose ps
    

  
or 
    
    
    docker ps
    

  
![How to install MariaDB in Docker - 6](https://dx86q6oq7ry0e.cloudfront.net/uploads/media/blog/a48@server-panel.net/2022/11/01/1669748438_9.png)  
To view the logs, use the command 
    
    
    docker logs -f mariadb
    

  
  
You can also perform the installation directly in docker:
    
    
    docker run -d --name mariadb -e MARIADB_USER=admin -e MARIADB_PASSWORD=your_password -e MARIADB_ROOT_PASSWORD=your_strong_pass mariadb:10.8
    

  
  
You can also install this version of the database mariadb:10.8 along with phpMyAdmin and link it to it. Let's see how to do this.  
  
We will edit the created docker-compose.yaml file.
    
    
    vim docker-compose.yaml
    

  
  
We will add the following structure below:
    
    
    version: '3.1'
    
    services:
      mariadb:
        container_name: mariadb
        image: mariadb:10.8
        ports:
            - 3310:3306
        environment:
            MARIADB_USER: admin
            MARIADB_PASSWORD: your_password
            MARIADB_ROOT_PASSWORD: your_strong_pass
        restart: always
    
      phpmyadmin:
        image: phpmyadmin
        restart: always
        ports:
          - 8090:80
        environment:
          - PMA_HOST=mariadb
        depends_on:
          - mariadb

  
In the **phpmyadmin** section, we added the **phpmyadmin** image, specified port **8090** , but now it will be linked to a specific database server, namely the one we installed/deployed **mariadb:10.8**.  
This parameter is specified in the **environment** block where: **PMA_HOST=mariadb** \- points to the **mariadb** container/block described above in this file.  
The **depends_on:** directive indicates the dependency of the start/run on the **mariadb** container. This means that until the container with **mariadb** starts, the container with **phpmyadmin** will not be started. We can start **phpmyadmin** and mariadb with one command. 
    
    
    docker-compose up -d or **docker-compose up -d --force-recreate**
    

  
We check:
    
    
    docker-compose ps
    

  
![How to install MariaDB in Docker - 7](https://dx86q6oq7ry0e.cloudfront.net/uploads/media/blog/a48@server-panel.net/2022/11/01/1669808417_docker-maria-admin.png)  
In this way, you can install the version of the MariaDB or MySQL database that you need.   
  
How to install Postgres and pgadmin4 in Docker can be read in the article [How to install PostgreSQL and pgAdmin in Docker.](https://zomro.com/rus/blog/faq/283-kak-ustanovit-postgresql-i-pgadmin-v-docker)

Similar articles:

[How to Install and Configure IIS FTP Server on Windows Server 2019](https://zomro.com/blog/faq/315-kak-ustanovit-i-nastroit-ftp-server-iis-na-windows-server-2019) [MacOS: How to perform MTR check](https://zomro.com/blog/faq/101-macos-kak-vypolnit-proverku-mtr) [Disable UDP for RDP connections to Windows Server](https://zomro.com/blog/faq/429-dissable-udp-for-rdp-on-windows) [Resetting WordPress Admin Password via Console in Linux Ubuntu or CentOS 7](https://zomro.com/blog/faq/335-resetting-wordpress-admin-password-via-console-in-linux-ubuntu-or-centos-7) [How to Install Docker on Centos 7](https://zomro.com/blog/faq/287-kak-ustanovit-docker-na-centos-7)

[ Virtual hosting from €3.98/mon ](/virtual)
