Community Solution

Install MariaDB on CasaOS or ZimaOS With Persistent Data

A 2023 CasaOS tutorial introduced MariaDB as a central database service for self-hosted applications.

Bottom Line: Treat MariaDB as Persistent Data, Not Just Another Disposable Container

The old CasaOS post introduced MariaDB as a central database for self-hosted apps. The current deployment principle is still valid, but the important part is not clicking Install—it is pinning a sensible image version, setting initialization credentials once, and mapping the database directory to persistent storage.

Use the Official MariaDB Container as the Baseline

services:
  mariadb:
    image: mariadb:lts
    restart: unless-stopped
    environment:
      MARIADB_ROOT_PASSWORD: change-this-now
      MARIADB_DATABASE: appdb
      MARIADB_USER: appuser
      MARIADB_PASSWORD: change-this-too
    volumes:
      - /path/to/mariadb:/var/lib/mysql
    ports:
      - "3306:3306"

MariaDB's container documentation describes the official image and its version tags. The image environment-variable reference explains the MARIADB_* settings.

Initialization Variables Only Matter on a Fresh Data Directory

If /var/lib/mysql already contains a database, changing MARIADB_ROOT_PASSWORD or MARIADB_DATABASE in Compose does not rebuild the existing instance. This is a common reason people think “the new password did nothing.”

The MariaDB hardware guide covers sizing and storage placement.

Do Not Publish Port 3306 to the Internet

If only local containers need MariaDB, keep them on the same Docker network and omit the host port entirely. If LAN clients need access, bind it only where required and create database users with narrow host and privilege scopes.

Use Adminer for Management, Not as the Database

Adminer is only a web UI. Your schema, users and data live in MariaDB. The Adminer hardware guide is useful once the database itself is healthy.

Back Up the Database, Not Just the Compose File

A Compose file can recreate the container. It cannot recreate your data. Back up the persistent database directory or use logical dumps, then test a restore before upgrading major versions.