Table of contents
Docker is a buzz word you have most probably seen in the news. I’m not going to enter in the definition/explanations of this lightweight virtualization solution, using containers, as there are already plenty of very good documents on Internet.
My idea when testing docker was to understand if I could be able to create a small sandbox with latest MariaDB or MySQL release without the hassle of creating the required filesystems, installing the binaries, creating the instance. In other word play with latest release of many tools without working hard to install and configure them.
And yes it is possible !! I have been really impressed by the simplicity to have something working as expected with Docker. I have tested MariaDB 10.1 that was in beta as the time of writing this post…
This blog post has been done using a virtual machine running under VirtualBox with Oracle Linux Server release 7.0. Docker release available at that time was 1.3.3.
The lazy approach is always to use the packages provided by your Linux distribution:
[root@server3 ~]# yum install docker docker-registry
Start it with:
[root@server3 ~]# systemctl start docker [root@server3 ~]# docker version Client version: 1.3.3 Client API version: 1.15 Go version (client): go1.3.3 Git commit (client): 4e9bbfa/1.3.3 OS/Arch (client): linux/amd64 Server version: 1.3.3 Server API version: 1.15 Go version (server): go1.3.3 Git commit (server): 4e9bbfa/1.3.3
As a complementary configuration I had to fight with certificates, docker search command look in Docker registry for available packages. You can also go to https://registry.hub.docker.com/, favor the official and well rated images:
[root@server3 ~]# docker search mariadb 2015/02/12 17:17:33 Error response from daemon: Get https://index.docker.io/v1/search?q=mariadb: dial tcp: lookup index.docker.io: no such host
Configured my web proxy and credentials:
[root@server3 ~]# cat /etc/sysconfig/docker OPTIONS=--selinux-enabled HTTP_PROXY=http://account:firstname.lastname@example.org:proxy_port http_proxy=$HTTP_PROXY HTTPS_PROXY=$HTTP_PROXY https_proxy=$HTTP_PROXY export HTTP_PROXY HTTPS_PROXY http_proxy https_proxy
Doing a test with Docker 1.12.3 the configuration is now slightly different:
[root@server3 ~]# mkdir -p /etc/systemd/system/docker.service.d [root@server3 ~]# vi /etc/systemd/system/docker.service.d/docker.conf [root@server3 ~]# cat /etc/systemd/system/docker.service.d/docker.conf [Service] Environment="HTTP_PROXY=http://account:email@example.com:proxy_port/"
This resolved my proxy issue (unknown host) but this time I had a certificate issue:
[root@server3 ~]# docker search mariadb 2015/02/13 12:31:52 Error response from daemon: Get https://index.docker.io/v1/search?q=mariadb: x509: certificate signed by unknown authority
I’m not at all expert in this area but found a nice url (see references) explaining that my proxy server is replacing the final web site certificate by its own (so certificate authority not part of standard authorized ones). So exported my proxy certificate (Zscaler product) from my web browser:
Chose DER-encoded binary X.509 format. Transferred the file to my guest machine under /tmp and executed:
[root@server3 ~]# cp /tmp/za.cer /etc/pki/ca-trust/source/anchors/ [root@server3 ~]# update-ca-trust extract
Then restarted docker and everything went well this time:
[root@server3 ~]# systemctl restart docker [root@server3 ~]# docker search mariadb NAME DESCRIPTION STARS OFFICIAL AUTOMATED mariadb MariaDB is a community-developed fork of M... 47 [OK] dockerfile/mariadb Trusted automated MariaDB (https://mariadb... 32 [OK] paintedfox/mariadb A docker image for running MariaDB 5.5, a ... 24 [OK] fedora/mariadb 22 [OK] tutum/mariadb MariaDB image - listens in port 3306. For ... 11 [OK] tianon/mariadb ♪ "I just met a girl named Maria!" ♫ 5 [OK] maxexcloo/mariadb Docker service container with MariaDB inst... 3 [OK] dylanlindgren/docker-mariadb Docker image for MariaDB 3 [OK] hachque/mariadb 1 [OK] cosmicq/openstack-mariadb (project not complete) MariaDB and PHPMyAd... 1 [OK] needo/mariadb 1 [OK] seetheprogress/mariadb MariaDB image provided by SeeTheProgress u... 1 [OK] marklee77/mariadb 0 [OK] partlab/ubuntu-mariadb Docker image to run an out of the box Mari... 0 [OK] mmckeen/mariadb MariaDB image based on openSUSE 13.1 0 [OK] million12/mariadb MariaDB 10 on CentOS-7 with UTF8 defaults 0 [OK] etna/mariadb 0 [OK] dasrick/fedora-mariadb MariaDB image - port 3306 - based on Fedora20 0 [OK] m0ikz/mariadb 0 [OK] gchiam/mariadb MariaDB on Docker. Built from https://gith... 0 [OK] aostanin/mariadb 0 [OK] combro2k/mariadb 0 [OK] bnchdrff/mariadb 0 [OK] muzili/mariadb 0 [OK] spiritdev/mariadb MariaDB Dock built from spiritdev/ubuntu 0 [OK]
Docker package installation
To download packages, use (the -a option allows to download all versions, or you will get only latest GA one):
[root@server3 ~]# docker pull -a mariadb Pulling repository mariadb 69468eff0e53: Pulling dependent layers . .
[root@server3 ~]# docker images mariadb REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE mariadb 5.5.42 69468eff0e53 5 days ago 238.8 MB mariadb 5.5 69468eff0e53 5 days ago 238.8 MB mariadb 5 69468eff0e53 5 days ago 238.8 MB mariadb 10.1 69c9e7aa9778 5 days ago 262.9 MB mariadb 10.1.2 69c9e7aa9778 5 days ago 262.9 MB mariadb 10.0.16 461aa7f79c6a 5 days ago 257.6 MB mariadb latest 461aa7f79c6a 5 days ago 257.6 MB mariadb 10 461aa7f79c6a 5 days ago 257.6 MB mariadb 10.0 461aa7f79c6a 5 days ago 257.6 MB mariadb 5.5.41 902a37810c09 3 weeks ago 245.7 MB mariadb 10.0.15 bbe548cddf43 5 weeks ago 261.1 MB mariadb 5.5.40 6c6ba5cb73b1 3 months ago 245.6 MB mariadb 10.1.1 ad8dfc3a6047 3 months ago 270.8 MB
And that’s it, MariaDB Docker package is downloaded on your server…
Docker package testing
To run the docker images I inherit what’s in official MariaDB docker page:
[root@server3 ~]# docker run --name mariadb -e MYSQL_ROOT_PASSWORD=secure_password -d mariadb:10.1.2 ced16a97f5e5236e273df771fb18f674bbd8f8f53ebbe3907aef8a64be42480d [root@server3 ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES ced16a97f5e5 mariadb:10.1 "/docker-entrypoint. 19 seconds ago Up 18 seconds 3306/tcp mariadb
The container is called mariadb (–name), MYSQL_ROOT_PASSWORD environment is set (-e), the container will run in the background (-d) and I choose to run the 10.1.2 docker image (mariadb:10.1.2).
I will try to connect with an interactive session (MySQL client) to this running container. Again I inherit options from MariaDB official docker image:
- -i keep STDIN open and -t allocate a pseudo tty
- –name set a name to the container
- –rm remove the container after exit
- –link option is the most confusing one. From official documentation it is in the form of –link <name or id>:<alias>. <name or id> will be the name of my MariaDB container so mariadb and I thought alias could be anything I wish. But I was wrong, reading further the documentation I have seen that docker will create environment variables in the form of <alias>_PORT_<port>_<protocol>, example: MYSQL_PORT_3306_TCP_ADDR. So alias name must match environment variables name (in uppercase) you are using in mysql client to specify host IP address and MySQL listening port
[root@server3 ~]# docker run -it --link mariadb:mysql --name=mysql_client --rm mariadb sh \ -c 'exec mysql -h"$MYSQL_PORT_3306_TCP_ADDR" -P"$MYSQL_PORT_3306_TCP_PORT" -uroot -p"$MYSQL_ENV_MYSQL_ROOT_PASSWORD"' Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 4 Server version: 10.1.2-MariaDB-1~wheezy-wsrep-log mariadb.org binary distribution, wsrep_25.10.r4123 Copyright (c) 2000, 2014, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> select version(); +-----------------------------------+ | version() | +-----------------------------------+ | 10.1.2-MariaDB-1~wheezy-wsrep-log | +-----------------------------------+ 1 row in set (0.00 sec) MariaDB [(none)]>
In another session you can now see you MySQL client docker container running (as well as initial MariaDB one):
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 07e4b15c92ef mariadb:10 "\"/docker-entrypoin 6 seconds ago Up 4 seconds 3306/tcp mysql_client ced16a97f5e5 mariadb:10.1 "/docker-entrypoint. 7 days ago Up 43 hours 3306/tcp mariadb
You can also see the environment variables in MySQL client connected (and linked) to your MariaDB container:
[root@server3 ~]# docker run -it --link mariadb:mysql --name=mysql_client --rm mariadb sh -c 'exec mysql -h"$MYSQL_PORT_3306_TCP_ADDR" -P"$MYSQL_PORT_3306_TCP_PORT" -uroot -p"$MYSQL_ENV_MYSQL_ROOT_PASSWORD"' Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 10 Server version: 10.1.2-MariaDB-1~wheezy-wsrep-log mariadb.org binary distribution, wsrep_25.10.r4123 Copyright (c) 2000, 2014, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> \! env HOSTNAME=07e4b15c92ef MYSQL_ENV_MARIADB_VERSION=10.1.2+maria-1~wheezy SHLVL=0 HOME=/root MARIADB_MAJOR=10.0 TERM=xterm COLUMNS=207 MYSQL_PORT_3306_TCP_ADDR=172.17.0.2 MYSQL_ENV_MYSQL_ROOT_PASSWORD=secure_password PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin MYSQL_PORT_3306_TCP_PORT=3306 MYSQL_PORT_3306_TCP_PROTO=tcp MYSQL_ENV_MARIADB_MAJOR=10.1 MYSQL_PORT=tcp://172.17.0.2:3306 MYSQL_PORT_3306_TCP=tcp://172.17.0.2:3306 PWD=/ MYSQL_NAME=/mysql_client/mysql MARIADB_VERSION=10.0.16+maria-1~wheezy LINES=58
And again quite rapidly you are done and can start to play with MariaDB 10.1 in just few commands… The principle would have been exactly the same for MySQL 5.7 development release…
- Oracle Label Security (OLS) 12c installation and configuration - November 20, 2017
- Database Vault 12cR1 installation and configuration - October 23, 2017
- Data Redaction (DBMS_REDACT) with 12cR1 (18.104.22.168) - September 26, 2017
- Resolve ORA-01578 error with and without a backup - August 28, 2017
- ProxySQL high availability tutorial with MariaDB replication - July 24, 2017
- Orchestrator MySQL replication topology tool tutorial - June 26, 2017