Overview

This is a guide on setting up MariaDB on a Synology using a Docker image using the web based user interface. The DSM version this guide is based on is DSM 6.1.5-15254. Your mileage may vary with other versions. 

The official MariaDB container doesn’t include a database management tool. I suggest setting up a phpmyadmin Docker container to maintain the database. See my post Setting up phpmyadmin on Synology using Docker to setup a container for this purpose.

Prerequisites
  • Docker package installed on Synology.
  • Folder under the “docker” volume on the Synology to hold the configuration files and data for the MariaDB container
Installation Steps
Step 1 – Obtain the MariaDB Docker container image.

Open up Docker and go to the Registry.

Search for “mariadb” and click on the official MariaDB container image and click “Download”. The official container image has a nice little ribbon to identify it.

MariaDB Image Search

When it asks you to choose a tag, select “latest” and click “Select”.

Step 2 – Create the container from the image

Go to Image section in the Docker tool, highlight the MariaDB Docker container image and click “Launch”. This will start the container creation wizard.

Step 3 – Configure the General container settings

Give the container a name. By default it will be “mariadb1”, you can keep that or rename it to whatever you prefer.

Step 4 – Configure the Advanced Settings container settings

Once you have a name for the container, click on “Advanced Settings” to continue settings up the configuration values.

Under Advanced Settings click on “Enable auto-restart”.

Step 5 – Configure the Volume container settings

Click on the “Volume” tab.

If you don’t already have a folder to save the configuration files and data files for the container created under the docker folder on the Synology, create those. I recommend creating a folder called “mariadb” and under that create two additional subfolders, one called “config” and one called “data”.

The config folder will be used to allow you to easily create a custom configuration file if you want to in the future. For this basic it won’t be needed, but having the volume mapped will make it easy to do so in the future.

The data folder is where the database data is stored. I recommend using one of the various Synology tools to ensure this data is backed up. I use Cloud Sync combined with Backblaze B2.

Once the folders are created, map them to the container by clicking “Add Folder”. Expand the docker folder, expand the mariadb folder, and select config. In the mount path type “/etc/mysql/conf.d” (without the quotes). Click “Add Folder” again and navigate to the docker/mariadb/data folder and select that. In the mount path type “/var/lib/mysql”. When done correctly the volume mappings should look like the image below.

MariaDB Volume Mapping Settings

Step 6 – Configure the Port Settings container settings

Click on the “Port Settings” tab. Change “Local Port” from “Auto” to some other value under Port Settings. What you use depends on other services that might be running. Ultimately it doesn’t matter what you set it to as long as the port number is not already in use and the number is between 1024-65535. If you are making the the MariaDB site available from the Internet and it is behind your Internet router, don’t forget to setup a port forward rule to direct it to whatever port you pick.

If the MariaDB system will not be exposed to external networks and you are connecting to it via docker container linking, it should not matter if you leave this setting at Auto. Although I still suggest not using Auto and picking a static port.

Step 7 – Configure the Environment container settings

Click on the “Environment” tab. Two additional environment variables need to be added.

MYSQL_ROOT_PASSWORD – This is the root password for the database system.

MYSQL_DATABASE – This is the name of a database that will be created on startup for the first time. If you are planning to use this installation with WordPress, I suggest setting this to “wordpress” as it will make the WordPress setup simple.

If you do not plan on using Docker container linking, you will need to add additional variables to allow access to the database. These are explained in the container documentation referenced in the references section below.

Once configured the environment variables will look like the image below.

MariaDB Environment Variables Settings

Step 8 – Finalize and create the container

Click “Apply” to bring you back to the general settings and click “Next” to go to the final review. Review the settings to make sure you didn’t miss anything, and once ready click “Apply” to create the container.

References

https://hub.docker.com/_/mariadb/

 


3 Comments

dakilla · August 24, 2018 at 3:38 am

Hey, there is a little mistake in step 7. It has to be “mysql” not “my_sql” in your screenshot everything is fine.

jb510 · August 26, 2018 at 7:32 pm

Thanks for the guide!

One note, the environment variables should be
MYSQL_ROOT_PASSWORD
MYSQL_DATABASE

not MY_SQL

Tom · August 31, 2018 at 10:26 am

Thanks, I updated to correct for MY_SQL being wrong.

Leave a Reply

%d bloggers like this: