There are a couple of posts about setting up Percona XtraDB Cluster on Vagrant and Percona Server on MySQL Sandbox – those are two of the top tools used by the Percona Support team for testing and bug processing among other things.
In this post, however, I will show you how to use Docker with Percona Server on Ubuntu 12.04.
As per Docker’s official site:
Docker is an open-source engine that automates the deployment of any application as a lightweight, portable, self-sufficient container that will run virtually anywhere.
Docker containers can encapsulate any payload, and will run consistently on and between virtually any server. The same container that a developer builds and tests on a laptop will run at scale, in production*, on VMs, bare-metal servers, OpenStack clusters, public instances, or combinations of the above.
To install Docker on Ubuntu 12.04 you need to follow instructions from Docker’s official documentation:
http://docs.docker.io/installation/ubuntulinux/#ubuntu-precise-1204-lts-64-bit
After installing Docker, you may either download docker images via ‘docker pull’ and store docker images on your server so you can spin a new docker container in an instance or you may choose to do a ‘docker run’ on the terminal and implicitly download/store the specific docker image from index.docker.io and run the image afterward.
1 2 3 4 | root@Perconallc-Support / # docker images | grep centos centos centos6 0b443ba03958 2 weeks ago 297.6 MB centos latest 0b443ba03958 2 weeks ago 297.6 MB centos 6.4 539c0211cd76 13 months ago 300.6 MB |
Let us create a CentOS docker container by running the following command:
1 2 3 | root@Perconallc-Support / # docker run -i -t centos:latest bash bash-4.1# cat /etc/redhat-release CentOS release 6.5 (Final) |
As you may have noticed, we have just created a new interactive (-i) CentOS 6.5 docker container and ran bash in a single line of command. Detaching from the container is as easy as typing CTRL+p – CTRL+q, you’ll get to your terminal if you typed the right keys.
Verify the active containers:
1 2 3 | root@Perconallc-Support / # docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 202765d754b7 centos:centos6 bash 11 minutes ago Up 11 minutes elegant_rosalind |
To list all existing containers active or not use the following command:
1 2 3 4 | root@Perconallc-Support / # docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 202765d754b7 centos:centos6 bash 12 minutes ago Up 12 minutes elegant_rosalind aae47d193a22 centos:6.4 bash 2 hours ago Exited (1) 2 hours ago boring_bardeen |
To attach to the active docker container:
1 2 3 | root@Perconallc-Support / # docker attach 202765d754b7 bash-4.1# |
*Tip: Hit enter twice to get to the container’s bash prompt.*
Install Percona Server 5.6
Now that you have a working docker container you will then have to install the needed packages and repository.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | bash-4.1# rpm -Uhv https://www.percona.com/downloads/percona-release/percona-release-0.0-1.x86_64.rpm Retrieving https://www.percona.com/downloads/percona-release/percona-release-0.0-1.x86_64.rpm Preparing... ########################################### [100%] 1:percona-release ########################################### [100%] bash-4.1# yum install Percona-Server-server-56 Percona-Server-client-56 Percona-Server-shared-56 Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: ftp.hosteurope.de * extras: ftp.plusline.de * updates: ftp.plusline.de Setting up Install Process Resolving Dependencies --> Running transaction check ---> Package Percona-Server-client-56.x86_64 0:5.6.17-rel65.0.el6 will be installed --> Processing Dependency: /usr/bin/perl for package: Percona-Server-client-56-5.6.17-rel65.0.el6.x86_64 ---> Package Percona-Server-server-56.x86_64 0:5.6.17-rel65.0.el6 will be installed --> Processing Dependency: libaio.so.1(LIBAIO_0.1)(64bit) for package: Percona-Server-server-56-5.6.17-rel65.0.el6.x86_64 --> Processing Dependency: libaio.so.1(LIBAIO_0.4)(64bit) for package: Percona-Server-server-56-5.6.17-rel65.0.el6.x86_64 --> Processing Dependency: libaio.so.1()(64bit) for package: Percona-Server-server-56-5.6.17-rel65.0.el6.x86_64 ---> Package Percona-Server-shared-56.x86_64 0:5.6.17-rel65.0.el6 will be installed --> Running transaction check ---> Package libaio.x86_64 0:0.3.107-10.el6 will be installed ---> Package perl.x86_64 4:5.10.1-136.el6 will be installed --> Processing Dependency: perl-libs = 4:5.10.1-136.el6 for package: 4:perl-5.10.1-136.el6.x86_64 --> Processing Dependency: perl-libs for package: 4:perl-5.10.1-136.el6.x86_64 --> Processing Dependency: perl(version) for package: 4:perl-5.10.1-136.el6.x86_64 --> Processing Dependency: perl(Pod::Simple) for package: 4:perl-5.10.1-136.el6.x86_64 --> Processing Dependency: perl(Module::Pluggable) for package: 4:perl-5.10.1-136.el6.x86_64 --> Processing Dependency: libperl.so()(64bit) for package: 4:perl-5.10.1-136.el6.x86_64 --> Running transaction check ---> Package perl-Module-Pluggable.x86_64 1:3.90-136.el6 will be installed ---> Package perl-Pod-Simple.x86_64 1:3.13-136.el6 will be installed --> Processing Dependency: perl(Pod::Escapes) >= 1.04 for package: 1:perl-Pod-Simple-3.13-136.el6.x86_64 ---> Package perl-libs.x86_64 4:5.10.1-136.el6 will be installed ---> Package perl-version.x86_64 3:0.77-136.el6 will be installed --> Running transaction check ---> Package perl-Pod-Escapes.x86_64 1:1.04-136.el6 will be installed --> Finished Dependency Resolution Dependencies Resolved ======================================================================================================================================================================== Package Arch Version Repository Size ======================================================================================================================================================================== Installing: Percona-Server-client-56 x86_64 5.6.17-rel65.0.el6 percona 6.8 M Percona-Server-server-56 x86_64 5.6.17-rel65.0.el6 percona 19 M Percona-Server-shared-56 x86_64 5.6.17-rel65.0.el6 percona 714 k Installing for dependencies: libaio x86_64 0.3.107-10.el6 base 21 k perl x86_64 4:5.10.1-136.el6 base 10 M perl-Module-Pluggable x86_64 1:3.90-136.el6 base 40 k perl-Pod-Escapes x86_64 1:1.04-136.el6 base 32 k perl-Pod-Simple x86_64 1:3.13-136.el6 base 212 k perl-libs x86_64 4:5.10.1-136.el6 base 578 k perl-version x86_64 3:0.77-136.el6 base 51 k Transaction Summary ======================================================================================================================================================================== Install 10 Package(s) Total download size: 38 M Installed size: 158 M Is this ok [y/N]: y Downloading Packages: (1/10): Percona-Server-client-56-5.6.17-rel65.0.el6.x86_64.rpm | 6.8 MB 00:02 (2/10): Percona-Server-server-56-5.6.17-rel65.0.el6.x86_64.rpm | 19 MB 00:00 (3/10): Percona-Server-shared-56-5.6.17-rel65.0.el6.x86_64.rpm | 714 kB 00:00 (4/10): libaio-0.3.107-10.el6.x86_64.rpm | 21 kB 00:00 (5/10): perl-5.10.1-136.el6.x86_64.rpm | 10 MB 00:00 (6/10): perl-Module-Pluggable-3.90-136.el6.x86_64.rpm | 40 kB 00:00 (7/10): perl-Pod-Escapes-1.04-136.el6.x86_64.rpm | 32 kB 00:00 (8/10): perl-Pod-Simple-3.13-136.el6.x86_64.rpm | 212 kB 00:00 (9/10): perl-libs-5.10.1-136.el6.x86_64.rpm | 578 kB 00:00 (10/10): perl-version-0.77-136.el6.x86_64.rpm | 51 kB 00:00 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ Total 7.4 MB/s | 38 MB 00:05 Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Warning: RPMDB altered outside of yum. ** Found 2 pre-existing rpmdb problem(s), 'yum check' output follows: udev-147-2.51.el6.x86_64 has missing requires of /sbin/service udev-147-2.51.el6.x86_64 has missing requires of MAKEDEV >= ('0', '3.11', None) Installing : Percona-Server-shared-56-5.6.17-rel65.0.el6.x86_64 1/10 Installing : 1:perl-Pod-Escapes-1.04-136.el6.x86_64 2/10 Installing : 1:perl-Module-Pluggable-3.90-136.el6.x86_64 3/10 Installing : 4:perl-libs-5.10.1-136.el6.x86_64 4/10 Installing : 3:perl-version-0.77-136.el6.x86_64 5/10 Installing : 1:perl-Pod-Simple-3.13-136.el6.x86_64 6/10 Installing : 4:perl-5.10.1-136.el6.x86_64 7/10 Installing : Percona-Server-client-56-5.6.17-rel65.0.el6.x86_64 8/10 Installing : libaio-0.3.107-10.el6.x86_64 9/10 Installing : Percona-Server-server-56-5.6.17-rel65.0.el6.x86_64 10/10 ... Installed: Percona-Server-client-56.x86_64 0:5.6.17-rel65.0.el6 Percona-Server-server-56.x86_64 0:5.6.17-rel65.0.el6 Percona-Server-shared-56.x86_64 0:5.6.17-rel65.0.el6 Dependency Installed: libaio.x86_64 0:0.3.107-10.el6 perl.x86_64 4:5.10.1-136.el6 perl-Module-Pluggable.x86_64 1:3.90-136.el6 perl-Pod-Escapes.x86_64 1:1.04-136.el6 perl-Pod-Simple.x86_64 1:3.13-136.el6 perl-libs.x86_64 4:5.10.1-136.el6 perl-version.x86_64 3:0.77-136.el6 Complete! bash-4.1# /etc/init.d/mysql start Starting MySQL (Percona Server). SUCCESS! bash-4.1# mysql Welcome to the MySQL monitor. Commands end with ; or g. Your MySQL connection id is 1 Server version: 5.6.17-65.0-56 Percona Server (GPL), Release 65.0, Revision 587 Copyright (c) 2009-2014 Percona LLC and/or its affiliates Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or 'h' for help. Type 'c' to clear the current input statement. mysql> |
There you have it, a freshly installed Percona Server 5.6.17 on CentOS 6.5 Linux container. Yay!
You can now create a new MySQL user to access the server outside the container:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | mysql> grant all privileges on *.* to 'test_user'@'%' identified by 'test_pass'; Query OK, 0 rows affected (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) root@Perconallc-Support / # mysql -h 172.17.0.2 -utest_user -p Enter password: Welcome to the MySQL monitor. Commands end with ; or g. Your MySQL connection id is 4 Server version: 5.6.17-65.0-56 Percona Server (GPL), Release 65.0, Revision 587 Copyright (c) 2009-2014 Percona LLC and/or its affiliates Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or 'h' for help. Type 'c' to clear the current input statement. mysql> |
We’re basically following installation instructions for Percona Server from the documentation.
Just the same way as you would do on any server, you can install other equally important Percona software on the same container to complete your docker environment.
As an added bonus, you can contribute to the Docker Community by commiting your container and pushing it to the docker registry.
Summary
I’ve shown you how easy it is to spin a docker container and install Percona Server 5.6 in it. This is by far one of the fastest ways to create test/staging environments to simulate production servers. For further reading you may want to read Docker’s official documentation here.
I hope that this has piqued your interest to try it out yourself. And if that happens we would love to know how Percona Server and other Percona software perform on your docker environment. Cheers!
Hi,
At Intern Avenue we have created a plain image based on CentOS and Percona https://registry.hub.docker.com/u/internavenue/centos-percona/
or just execute “drush run -t internavenue/centos-percona”… Enjoy!
Hi Jericho,
Thanks for this tutorial! I found it looking for info about how people were running databases in Docker.
I’d be curious to get your thoughts on an opensource project that we’re working on to simplfy the deployment and migration of databases like Percona running inside Docker containers: https://github.com/ClusterHQ/flocker
You could use Flocker to deploy your Percona cluster to multiple nodes and then migrate the containers and their volumes around if you needed to, for instance, upgrade the ram on your host.
This is a 100% open-source project so I’d love to get your feedback on how we could make things easier for Percona users.
Cheers!
Michael
[email protected]
Hi Jericho,
Just wanted to follow up and let you know that we just released the first major point release of Flocker.
Flocker handles multi-node deployment, container migration along with associated volumes, and container networking so you (usually) don’t have to update DNS after a database migration.
The code is here (https://github.com/ClusterHQ/flocker), and we put together a tutorial for deploying and migrating MongoDB (http://docs.clusterhq.com/en/0.1.0/gettingstarted/tutorial/index.html). We’re working on a MySQL sample as well and would love to support Percona too. 🙂
Would love you thoughts if you have a minute.
@Michael Rikmas,
Thanks for taking the time to read this blog post!
Flocker looks very interesting and I would try it out sometime soon. Interested to check out your tutorial for deploying and migrating MySQL/Percona, also would be good to know if it can handle multi-node deployment and migration of Percona XtraDB Cluster nodes.
Cheers!
I thought you’d like to know that I created a Percona Server entry for the Dockerfile Hub project:
https://registry.hub.docker.com/u/dockerfile/percona/
This provides trusted, pre-built images for Docker, making it quicker and easier to build docker clusters.
Jericho, thanks for the article.
Do you please know if there’s a performance penalty when running mysqld using docker? I assume the performance should be the same, but I’m not sure, because I don’t know much about docker and OS interaction.
Thank you, Vojtech
@Vojtech,
You might want to look at this research report conducted by IBM on the performance comparison of virtual machines and Linux containers which shows benchmarks run using SysBench OLTP run against a single instance of MySQL 5.5.37:
http://domino.research.ibm.com/library/cyberdig.nsf/papers/0929052195DD819C85257D2300681E7B/$File/rc25482.pdf
Now I would assume there would be significant performance penalties when you run multiple docker containers on a single host machine as each docker container will try to compete with each other for resources, unless you restrict them in cgroups.
Please be aware though that this write-up is for test environments only, for production systems it would be a lot different and in fact it is not yet recommended (afaik) to use Docker in production.
Cheers!