Skip to content
Runbook

Install MariaDB on Docker

Open source SQL database, a community-developed drop-in replacement for MySQL.

Databasesqlrdbmsrelationaldatabaseacidmysql-compatible

Installation

Container (official image) · Docker
docker run -d --name mariadb -e MARIADB_ROOT_PASSWORD=secret -p 3306:3306 -v mariadbdata:/var/lib/mysql mariadb:11

Replace 'secret' with a strong password. The named volume mariadbdata persists the data.

Verify the installation

Verify
docker exec mariadb mariadb --version

Important files

TypePathDescription
data/var/lib/mysqlData directory INSIDE the container, to mount on a volume for persistence.

Default ports

3306

Command-line tools

  • mariadbInteractive SQL client, accessible via docker exec.
  • mariadb-adminAdministrative client, via docker exec.

Uninstall

Remove the container
docker rm -f mariadb

Does NOT delete the mariadbdata volume.

Also remove the data
docker volume rm mariadbdata

Irreversible: destroys all data.

Good to know

  • MARIADB_ROOT_PASSWORD is MANDATORY on first startup (MYSQL_ROOT_PASSWORD is also accepted for compatibility).
  • Without a volume, data is lost when the container is removed: always use a named volume or bind mount.
  • Useful variables: MARIADB_DATABASE, MARIADB_USER and MARIADB_PASSWORD create a database and user at startup.

Starting MariaDB with Docker

The official mariadb image provides a ready-to-use server. The command above runs a detached container, publishes port 3306, and stores data in the named volume mariadbdata. MARIADB_ROOT_PASSWORD is mandatory on first startup.

Data persistence

The internal data directory is /var/lib/mysql. Without a volume, data disappears when the container is removed. The named volume mariadbdata keeps your databases across recreations.

Customization and connection

Set MARIADB_DATABASE, MARIADB_USER, and MARIADB_PASSWORD to create a database and user at startup. Open a SQL shell with docker exec -it mariadb mariadb -u root -p; from the host, connect to localhost:3306 with any MySQL-compatible client.