Docker is ideal for rapid deployment of MariaDB. You first upload a suitable image. Then you configure and start the container with the desired settings. This means you test or develop independently of the host system in a controlled environment.
Benefits of MariaDB Docker environments
Docker provides a simple method to deploy MariaDB in isolated environments. You can quickly launch instances and test different versions independently. This saves you time, avoids conflicts with local installations, and creates repeatable conditions for development and testing.
Prerequisites
Before you begin, make sure the following prerequisites are met:
- Docker is installed and running on your system
- Access to a command line (Terminal, PowerShell, etc.) with admin rights
- Optional for MariaDB: Docker Compose, for more complex configurations
Managed databases
Managed and secure databases
- Flexible solutions, tailored to your needs
- Professional-grade architecture, managed by experts
- Hosted in Europe, in accordance with the strictest data protection standards
Installing MariaDB in Docker: Step-by-Step Guide
Find out how to install MariaDB in Docker in just a few steps below. How to configure Docker upstream is detailed in our Docker tutorial.
Step 1: Install Docker
If you don't have Docker installed yet, you can configure it via the installation script official :
curl -sSL https://get.docker.com/ | sh
bash
On Windows or macOS, it is recommended to use Docker Desktop. After successful installation, check its correct operation with:
The output should show a version number, e.g. Docker version 27.5.1, build cb74dfcd. If so, you have configured Docker correctly.
Step 2: Download the MariaDB image
Now download theMariaDB Docker image official since Docker Hub. This contains a fully preconfigured MariaDB instance.
docker pull mariadb:latest
bash
If you prefer a specific version, you can also specify it explicitly, for example:
docker pull mariadb:10.11
bash
You can then check all locally stored images with the following command:
The line with mariadb and the corresponding tag should appear in the list.
Step 3: Start the MariaDB container in Docker
Now create the container. To do this, use the command:
docker run --name mariadb-container -e MYSQL_ROOT_PASSWORD=password -d -p 3306:3306 mariadb:latest
bash
--name mariadb-container: assigns a name to the container, under which it can be referenced in the system.-e MYSQL_ROOT_PASSWORD=password: sets the root password for the MariaDB database. You will need it later to log in.-d: starts the container in the background (detached mode), allowing you to free up your console.-p 3306:3306: Connects the default container database port to the same port on your local system, so you can access it through clients.
After running this command, Docker should start the container. To check its status, enter:
In the list of running containers, mariadb-container should appear with status Up. If the container is not working as expected, you can view the files log with :
docker logs mariadb-container
bash
The logs make it possible to identify possible configuration errors.
Step 4: Access MariaDB
As soon as the MariaDB Docker container is running, you can access the database with a MySQL compatible client like the standard MySQL tool or graphical tools like DBeaver, HeidiSQL or Beekeeper Studio.
On the command line, you can use the following command:
mysql -h 127.0.0.1 -P 3306 -u root -p
bash
You will be prompted to enter the password. Enter the one you defined with MYSQL_ROOT_PASSWORD.
If everything works, you will access the MariaDB console. There you can run SQL commands as per usual :
You will see the default bases and can create your own bases or tables.
Step 5: Secure persistent data with volumes
By default, data in the container is temporary. To secure your data during reboots or container changes, it is recommended to 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
-v mariadb_data:/var/lib/mysql creates a named Docker volume mariadb_data and links it to the directory where MariaDB stores its data.
You can view stored volumes at any time with the following command:
With the following command you can then inspect the contents of a volume:
docker volume inspect mariadb_data
bash
Step 6: Manage MariaDB with Docker Compose
For more complex setups, you can use Docker Compose. To do this, create a file docker-compose.yml with 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
Start the environment with:
MariaDB now runs in the background, with persistent storage and a preconfigured database.
Step 7: Stop, Start, and Delete a Container
With Docker, container management is very simple. You can stop or restart the container at any time MariaDB Docker without loss of data, provided you use volumes. Here are the commands to use.
Stop a container:
docker stop mariadb-container
bash
Start a container:
docker start mariadb-container
bash
Delete a container:
docker rm mariadb-container
bash
Delete a container with volume:
docker rm -v mariadb-container
bash
Step 8: Automatic container restart
So that your container MariaDB Docker restarts automatically after a reboot of the host system, you can define the reboot policy:
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 ensures that the container starts automatically after a system reboot, unless you stopped it manually.

