mariadb
Welcome back to the Selfhosters Blog! Today, we’re diving into an essential component for many self-hosting setups: the MariaDB docker image. MariaDB is a robust, scalable, and reliable drop-in replacement for MySQL. It’s widely used in self-hosted applications ranging from content management systems like WordPress to powerful analytics and custom apps that require a backend database.
What is MariaDB?
MariaDB is an open-source relational database management system (RDBMS) that was created by the original developers of MySQL after it was acquired by Oracle. It aims to remain free under the GNU GPL and delivers high compatibility with existing MySQL-based software while continuing to receive new features and performance improvements.
Why use MariaDB in Docker?
- Portability – run anywhere Docker is supported
- Isolation – your MariaDB database runs in its own isolated container
- Simplicity – easy backup, restore, and migration between systems
- Efficient updates – easily run the latest version
And thanks to LinuxServer.io’s maintained version, you get a well-maintained, production-ready MariaDB container out of the box.
How to Set It Up
First, make sure Docker and Docker Compose are installed on your host system. Then, create a new directory for your MariaDB setup and a docker-compose.yml
file. Here’s an example configuration from LinuxServer.io:
version: "3.8"
services:
mariadb:
image: lscr.io/linuxserver/mariadb:latest
container_name: mariadb
environment:
- PUID=1000
- PGID=1000
- MYSQL_ROOT_PASSWORD=yourRootPasswordHere
- TZ=Europe/London
- MYSQL_DATABASE=yourDatabaseName
- MYSQL_USER=yourUser
- MYSQL_PASSWORD=yourPassword
volumes:
- ./config:/config
ports:
- 3306:3306
restart: unless-stopped
Key Environment Variables
- MYSQL_ROOT_PASSWORD: sets the root password for MariaDB.
- MYSQL_DATABASE: allows you to specify a default database to be created.
- MYSQL_USER and MYSQL_PASSWORD: creates a new user with these credentials with access to the above database.
Volumes
The container stores its configuration and database files under the /config
directory within the container. Mount it to a local folder to ensure your data persists through upgrades.
Using MariaDB
Once your container is running, you can connect to your MariaDB instance from another self-hosted application such as Nextcloud, WordPress, or a custom app. Use the IP address of your Docker host (or localhost
if on the same machine), port 3306
, and the username and password you configured.
Backing Up and Restoring
Because your database files are stored under the ./config
volume, backing them up is as simple as copying this directory. For more advanced backups, you can use mysqldump
commands within the container to export SQL files and version them however you’d like.
Final Thoughts
The LinuxServer.io MariaDB docker image is a fantastic starting point for anyone looking to self-host applications with a dependable and performance-oriented database. With Docker Compose, getting started takes minutes — and you’re left with a flexible, upgradeable setup you control.
For further configuration options and examples, check out the official documentation here: https://docs.linuxserver.io/images/docker-mariadb
Happy selfhosting, and I will see you in the next post!
Leave a Reply