MariaDB Enterprise in Docker

You are viewing an old version of this category. View the current version here.

Introduction

MariaDB Corporation hosts a Docker registry that will expand over time to include a number of Docker images that support a variety of deployment scenarios and replication/clustering topologies.

The first image available from the MariaDB Corporation Docker registry is mariadb-enterprise-server. This image provides a MariaDB Enterprise Server package that will allow you to deploy a standalone server or a number of replication topologies that use binlog-based replication. MariaDB Enterprise Cluster is not supported in Docker at this time.

This document provides a brief introduction to Docker and a walk-through of how to use the MariaDB Enterprise Server Docker image.

What is Docker?

Docker is a technology that utilizes several features of the Linux kernel to compartmentalize applications and services in "containers". This improves security by preventing applications and services from interfering with each other in unexpected ways.

The MariaDB Corporation Docker Registry

MariaDB Corporation hosts its own Docker registry, which means that users retrieve Docker images for MariaDB Enterprise from us. The MariaDB Corporation Docker Registry is located at https://docker.mariadb.com, and it requires authentication.

You should use your MariaDB Enterprise Download Token to access images in the MariaDB Corporation Docker Registry.

To find your MariaDB Enterprise Download Token, log in to [https://mariadb.com/my_portal|My Portal Dashboard] and copy the correct Download Token for the contract under which you wish to deploy your Docker container.

Logging in to the MariaDB Corporation Docker Registry

In order to retrieve images from the MariaDB Corporation Docker Registry, you should first log in. You do this using the docker login command with your MariaDB Enterprise Download Token as the username, like this:

docker login -u <token> -p none -e none https://docker.mariadb.com

The MariaDB Enterprise Server Docker Image

The MariaDB Enterprise Server Docker Image provides a single instance of MariaDB Enterprise Server 10.0. You can connect multiple containers together to form replication topologies. MariaDB Enterprise Cluster is not supported at this time.

Deploying a container: the simple case

Deploying a Docker container from the MariaDB Enterprise Server Docker Image requires a simple docker run command. For example:

# docker run -d docker.mariadb.com/mariadb-enterprise-server
9ef6f3017e46ad7958b1a8be6032773c346a7055352aca1048235e0d96473b1c

# docker exec -ti 9ef6f3017e46ad7958b1a8be6032773c346a7055352aca1048235e0d96473b1c mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 10.0.17-MariaDB-enterprise-log MariaDB Enterprise Certified Binary

Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>

Deploying a container: publishing port 3306

You can also "publish" the port from the MariaDB Enterprise Server instance running in the container, so that you can access it from the Docker host or from other hosts on the network.

# c=$(docker run -d -P docker.mariadb.com/mariadb-enterprise-server)
# hostaddr=$(docker inspect "$c" | jq -r .[0].NetworkSettings.Gateway)
# port="$(docker port "$c" 3306/tcp)"
# docker exec "$c" mysql -e "grant all privileges on *.* to 'root'@'$hostaddr' identified by 'MyNewPass'"
# mysql -h "${port%:*}" -P "${port#*:}" -pMyNewPass
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 10.0.17-MariaDB-enterprise-log MariaDB Enterprise Certified Binary

Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>

Deploying a container: binding/mounting volumes

The MariaDB Enterprise Server Docker Image supports several "volumes". This allows sharing directories between the Docker host and containers running on that host as well as between containers themselves. The volumes used by the MariaDB Enterprise Server Docker Image include these:

  • /var/lib/mysql, the MariaDB datadir
  • /var/lib/mariadb-socket, the directory where the MariaDB socket file is kept
  • /var/lib/mariadb-load-data, a directory that can be used for data files to be consumed via LOAD DATA INFILE

Filesystem permissions

Filesystem and SELinux permissions for Docker volumes can be tricky. Permissions for volumes are based on UID and GID, not username and group name. The result of this is that you must change the permissions for directories on the host to match the UID and GID of users inside the container. This can have strange results on the host.

The mysqld process inside the container runs as user "mysql" in group "mysql". The MariaDB Enterprise Server Docker Image includes a convenience script to show you the correct UID and GID:

# docker run --rm --entrypoint=my_print_uidgid docker.mariadb.com/mariadb-enterprise-server
999:999

To create a directory on the host that we want to bind/mount as a Docker volume, we must use chown to give it the correct permissions:

# mkdir mariadb-socket
# chown "$(docker run --rm --entrypoint=my_print_uidgid docker.mariadb.com/mariadb-enterprise-server)" mariadb-socket

If you have SELinux enabled, you also need to re-label the directory to have the correct SELinux context:

# chcon -t svirt_sandbox_file_t mariadb-load-data mariadb-datadir mariadb-socket

Mounting the mariadb-socket volume

Now, run the container with the new volume:

# c=$(docker run -d -v "$PWD/mariadb-socket":/var/lib/mariadb-socket docker.mariadb.com/mariadb-enterprise-server)
# ls mariadb-socket/
mariadb.sock
# docker exec "$c" mysqladmin password 'MyNewPassword'

We can get the randomly-generated root password from inside the .my.cnf file of the running volume and use that to log in to the server using the socket file in the mounted volume:

# mysql -S ./mariadb-socket/mariadb.sock -pMyNewPassword
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 10
Server version: 10.0.17-MariaDB-enterprise-log MariaDB Enterprise Certified Binary

Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>

Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.