Docker makes it easy to set up MariaDB quickly. First, download the ap­pro­pri­ate image. Then configure and start the container with your preferred settings. This lets you work in a con­trolled en­vir­on­ment, in­de­pend­ent of your computer’s main system.

What are the ad­vant­ages of running MariaDB in Docker?

Docker provides a straight­for­ward way to run MariaDB in isolated en­vir­on­ments. You can start new MariaDB con­tain­ers quickly and try different versions without them in­ter­fer­ing with one another. This saves time, avoids conflicts with local in­stall­a­tions and ensures con­sist­ent con­di­tions for de­vel­op­ment and testing.

What are the re­quire­ments?

Before getting started, make sure you have:

  • Docker is installed and running on your system
  • Access to a command line (Terminal, Power­Shell etc.) with ad­min­is­trat­or rights
  • Optional for MariaDB: Docker Compose for more complex setups
Managed Databases
Time-saving database services
  • En­ter­prise-grade ar­chi­tec­ture managed by experts
  • Flexible solutions tailored to your re­quire­ments
  • Hosted in the UK under strict data pro­tec­tion le­gis­la­tion

How to install MariaDB in Docker

Below, we walk you through in­stalling MariaDB in Docker in just a few steps. For details on setting up Docker itself, see our Docker Tutorial.

Step 1: Install Docker

If you haven’t installed Docker yet, use the official in­stall­a­tion script:

curl -sSL https://get.docker.com/ | sh
bash

For Windows or macOS, Docker Desktop is re­com­men­ded. After in­stall­a­tion, check this with:

docker --version
bash

You should see a version number such as Docker version 27.5.1, build cb74dfcd. This means Docker has been installed correctly.

Step 2: Download MariaDB image

Now download the official MariaDB Docker image from Docker Hub. This is a ready-to-use version of MariaDB:

docker pull mariadb:latest
bash

To get a specific version, use:

docker pull mariadb:10.11
bash

You can then check all locally stored images with the following command:

docker images
bash

Look for mariadb and the version tag in the list.

Step 3: Start the MariaDB Docker container

Create the container, using the following command:

docker run --name mariadb-container -e MYSQL_ROOT_PASSWORD=password -d -p 3306:3306 mariadb:latest
bash
  • --name mariadb-container: Gives the container a name, so you can refer to it later.
  • -e MYSQL_ROOT_PASSWORD=password: Sets the root password for the MariaDB database. You will need this later to log in.
  • -d: Runs the container in the back­ground (in detached mode), so your console remains free.
  • -p 3306:3306: Makes the database ac­cess­ible on your computer through port 3306.

After running this command, Docker should start the container. To check the status, enter:

docker ps
bash

In the list of running con­tain­ers, mariadb-container should appear with the status Up. If the container isn’t running, view its log files for troubleshoot­ing with:

docker logs mariadb-container
bash

The log output helps you identify any con­fig­ur­a­tion errors.

Step 4: Access MariaDB

Once the MariaDB Docker container is running, you can connect with a MySQL-com­pat­ible client, such as the MySQL command line tool or graphical tools like DBeaver, HeidiSQL and Beekeeper Studio.

For example, from the command line:

mysql -h 127.0.0.1 -P 3306 -u root -p
bash

Enter the password you set with MYSQL_ROOT_PASSWORD.

If suc­cess­ful, you’ll have access to the MariaDB console and can run SQL commands such as:

SHOW DATABASES;
sql

This will list the default databases. You can then create your own databases and tables.

Step 5: Use volumes to keep data between container runs

By default, container data is deleted when the container is removed. To secure your data, use a volume:

docker run --name mariadb-container -e MYSQL_ROOT_PASSWORD=password -d \
    -v mariadb_data:/var/lib/mysql \
    -p 3306:3306 mariadb:latest
bash

Here -v mariadb_data:/var/lib/mysql creates a Docker volume named mariadb_data for storing MariaDB data.

You can view the stored volumes at any time with this command:

docker volume ls
bash

And use this command to inspect a volume:

docker volume inspect mariadb_data
bash

Step 6: Manage MariaDB with Docker Compose

For more complex setups, you should use Docker Compose. First create a file named docker-compose.yml and add the following content:

version: '3.1'
services:
    mariadb:
        image: mariadb:latest
        container_name: mariadb-compose
        environment:
            MYSQL_ROOT_PASSWORD: password
            MYSQL_DATABASE: example_db
        ports:
            - "3306:3306"
        volumes:
            - mariadb_data:/var/lib/mysql
volumes:
    mariadb_data:
yaml

Then, start the en­vir­on­ment with:

docker-compose up -d
bash

MariaDB will run in the back­ground, with saved data and a pre­con­figured database.

Step 7: Stop, start and remove container

You can manage the MariaDB Docker container at any time. If you’ve set up a volume, you can stop or restart the container without losing your database files.

Stop container:

docker stop mariadb-container
bash

Start container:

docker start mariadb-container
bash

Remove container:

docker rm mariadb-container
bash

Remove container and its volume:

docker rm -v mariadb-container
bash

Step 8: Enable automatic

If you want your MariaDB Docker container to start auto­mat­ic­ally whenever your computer restarts, use the --restart option when creating it:

docker run --name mariadb-container -e MYSQL_ROOT_PASSWORD=password \
    -v mariadb_data:/var/lib/mysql \
    -p 3306:3306 \
    --restart unless-stopped \
    -d mariadb:latest
bash

--restart unless-stopped tells Docker to start the container auto­mat­ic­ally after a reboot, unless you’ve stopped it manually.

Go to Main Menu