# Self-host MariaDB

> The MariaDB database server on the official image, with a persistent volume, generated root and user passwords, and an application database. It is not published on the host, so reach it from other services in this project at mariadb:3306.

- Page: https://levelrail.com/templates/mariadb/
- JSON: https://levelrail.com/templates/mariadb.json
- Category: Database Tools
- Licence: GPL-2.0-only (Copyleft license)
- Source: https://github.com/MariaDB/server
- Upstream docs: https://mariadb.com/kb/en/documentation/

## Requirements
- Memory: about 512 MiB
- amd64: unknown, arm64: unknown
- Needs configuration before start: no
- Pinned image tag: 11.4.13

## Services

| Service | Image | Tag | Ports | Volumes |
| --- | --- | --- | --- | --- |
| mariadb | mariadb | 11.4.13 | 3306 | mariadb_data -> /var/lib/mysql |

## Environment

| Service | Variable | Kind |
| --- | --- | --- |
| mariadb | MARIADB_DATABASE | preset |
| mariadb | MARIADB_PASSWORD | generated |
| mariadb | MARIADB_ROOT_PASSWORD | generated |
| mariadb | MARIADB_USER | preset |

## Deploy

### CLI

```bash
levelrail-cli templates install mariadb --name my-mariadb
```

Add --domain SERVICE=HOST to serve a service on your own domain, for example --domain mariadb=app.example.com.

### API

```bash
curl -X POST -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
  https://levelrail.example.com/api/v1/service-templates/mariadb/install \
  -d '{
    "name": "my-mariadb"
  }'
```

Create a token in the dashboard first. Name, env and domains are the request fields.

## First run
1. Read the generated passwords from the app secrets, then connect with the application user or as root from a service in the same project.

## Questions

### Can I deploy MariaDB on Dokploy or Dokku?

The services and pinned images on this page can be run on any Docker host. The public Dokploy templates list we compared does not have an entry with the same id for MariaDB, so on Dokploy you would use a Docker Compose application with the file from this page. Dokku deploys container images with its own commands, so the pinned image mariadb:11.4.13 is what you deploy there.

Self-host MariaDB, MariaDB docker compose file, deploy MariaDB on a VPS: this page lists the pinned image, ports, volumes and the commands for each.
