Thursday, May 4, 2017

Open Source: Dockerfile for MariaDB on CentOS

Previously I need to have a version of mariadb running on Windows without any installation, during the process i developed two solutions:
  • a standalone mariadb in java using embedded mariadbs server 
  • a docker image which that automates the configuration of mariadb on centos container
The dockerfile and associated files which build and configure mariadb for centos is now released as an open-source project in github:


The features and usage of this docker image is described below:



Docker Project logo Mariadb Project logo

Features

  • The docker image is built from centos/systemd
  • Allow user to create a database in the mariadb if the database is not created when docker container is started
  • Allow user to configure the password for the 'root' account of mariadb
  • Allow user to user to ssh into the container to start or stop the mariadb if needed
  • Allow user to configure the mariadb such as default encoding, maximum connections, max packat allowed

Usage

Git clone the project to your local computer:
git clone https://github.com/chen0040/dockerfile-centos-mariadb.git

Build the mariadb docker image

Run the following command from the root folder of the project to build your own docker image:
docker build -t xschen/mariadb .
You can optionally save the image by running the following command:
docker save -o xschen-mariadb.img xschen/mariadb

Create and start the docker container

docker run -it --name=xschen-mariadb -u 0  -d -p 3306:3306 xschen/mariadb
Now you should be able to connect to the mariadb from your local computer at the port 3306,
an example of the data source url will be:
jdbc:mysql://127.0.0.1:3306/my_database?useSSL=false&useUnicode=yes&characterEncoding=UTF-8
Note that 127.0.0.1 may need to be replaced with the ip of your docker machine VM (depends how you set up your docker machine)

Start and stop the mariadb in the container

To start or stop the mariadb in the container, make sure that the container is running, then run the following command from your local computer:
docker exec -it xschen-mariadb /bin/bash
Once in the container, run the following command to start or stop the mariadb:
$ cd /home/xschen
$ sudo ./start.sh
$ cd /home/xschen
$ sudo ./stop.sh

No comments:

Post a Comment