Skip to content

Deploying a MariaDB App

MariaDB is a popular open-source relational database management system, fully compatible with MySQL. It is widely used for web applications and enterprise solutions due to its performance, reliability, and robust feature set. This guide explains how to deploy a MariaDB instance on Klutch.sh using a Dockerfile, including how to attach persistent storage for your data.


Prerequisites

  • A Klutch.sh account (sign up here)
  • A GitHub repository for your MariaDB Docker setup
  • Basic knowledge of Docker and Git

1. Prepare Your MariaDB Project

Create a new directory for your MariaDB project and initialize a Git repository:

Terminal window
mkdir mariadb-docker && cd mariadb-docker
git init

2. Sample Dockerfile

Create a Dockerfile with the following content:

FROM mariadb:latest
# Expose the default MariaDB port
EXPOSE 3306

3. Configure Persistent Volumes

To ensure your database data persists across deployments and restarts, attach a persistent volume in the Klutch.sh dashboard:

  1. In your app settings on Klutch.sh, go to the Volumes section.
  2. Create a new volume (e.g., mariadb-data).
  3. Mount the volume to /var/lib/mysql in your container.

Your volume mount configuration should look like:

/var/lib/mysql ← mariadb-data

4. Set Environment Variables

Set the following environment variables in your Klutch.sh app settings:

  • MYSQL_ROOT_PASSWORD (required, set a strong root password)
  • MYSQL_DATABASE (optional, name of a default database to create)
  • MYSQL_USER (optional, a user to create)
  • MYSQL_PASSWORD (optional, password for the new user)

5. Deploy to Klutch.sh

  1. Push your code (including the Dockerfile) to your GitHub repository.
  2. In the Klutch.sh dashboard, create a new app and connect your repository.
  3. Set the build context and Dockerfile path if different from the root.
  4. Set the app port to 3306 (or the port exposed in your Dockerfile).
  5. Add the required environment variables.
  6. Attach the persistent volume to /var/lib/mysql.
  7. Click “Create” to deploy. Klutch.sh will build and run your MariaDB container.

6. Post-Deployment

  • Connect to your MariaDB instance using the Klutch.sh app URL and port 3306.
  • Use a MySQL/MariaDB client or application to manage your databases.

Resources