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:
mkdir mariadb-docker && cd mariadb-dockergit init
2. Sample Dockerfile
Create a Dockerfile
with the following content:
FROM mariadb:latest
# Expose the default MariaDB portEXPOSE 3306
3. Configure Persistent Volumes
To ensure your database data persists across deployments and restarts, attach a persistent volume in the Klutch.sh dashboard:
- In your app settings on Klutch.sh, go to the Volumes section.
- Create a new volume (e.g.,
mariadb-data
). - 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
- Push your code (including the Dockerfile) to your GitHub repository.
- In the Klutch.sh dashboard, create a new app and connect your repository.
- Set the build context and Dockerfile path if different from the root.
- Set the app port to
3306
(or the port exposed in your Dockerfile). - Add the required environment variables.
- Attach the persistent volume to
/var/lib/mysql
. - 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.