How to install MariaDB via Docker
Docker makes it easy to set up MariaDB quickly. First, download the appropriate image. Then configure and start the container with your preferred settings. This lets you work in a controlled environment, independent of your computer’s main system.
What are the advantages of running MariaDB in Docker?
Docker provides a straightforward way to run MariaDB in isolated environments. You can start new MariaDB containers quickly and try different versions without them interfering with one another. This saves time, avoids conflicts with local installations and ensures consistent conditions for development and testing.
What are the requirements?
Before getting started, make sure you have:
- Docker is installed and running on your system
- Access to a command line (Terminal, PowerShell etc.) with administrator rights
- Optional for MariaDB: Docker Compose for more complex setups
- Enterprise-grade architecture managed by experts
- Flexible solutions tailored to your requirements
- Hosted in the UK under strict data protection legislation
How to install MariaDB in Docker
Below, we walk you through installing 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 installation script:
curl -sSL https://get.docker.com/ | shbashFor Windows or macOS, Docker Desktop is recommended. After installation, check this with:
docker --versionbashYou 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:latestbashTo get a specific version, use:
docker pull mariadb:10.11bashYou can then check all locally stored images with the following command:
docker imagesbashLook 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:latestbash--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 background (in detached mode), so your console remains free.-p 3306:3306: Makes the database accessible on your computer through port 3306.
After running this command, Docker should start the container. To check the status, enter:
docker psbashIn the list of running containers, mariadb-container should appear with the status Up. If the container isn’t running, view its log files for troubleshooting with:
docker logs mariadb-containerbashThe log output helps you identify any configuration errors.
Step 4: Access MariaDB
Once the MariaDB Docker container is running, you can connect with a MySQL-compatible 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 -pbashEnter the password you set with MYSQL_ROOT_PASSWORD.
If successful, you’ll have access to the MariaDB console and can run SQL commands such as:
SHOW DATABASES;sqlThis 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:latestbashHere -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 lsbashAnd use this command to inspect a volume:
docker volume inspect mariadb_databashStep 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:yamlThen, start the environment with:
docker-compose up -dbashMariaDB will run in the background, with saved data and a preconfigured 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-containerbashStart container:
docker start mariadb-containerbashRemove container:
docker rm mariadb-containerbashRemove container and its volume:
docker rm -v mariadb-containerbashStep 8: Enable automatic
If you want your MariaDB Docker container to start automatically 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:latestbash--restart unless-stopped tells Docker to start the container automatically after a reboot, unless you’ve stopped it manually.

