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.

Let us create a CentOS docker container by running the following command:

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:

To list all existing containers active or not use the following command:

To attach to the active docker container:

*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.

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:

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!

7 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Janos Feher

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!

Michael Ferranti

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]

Michael

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.

Marcus Bointon

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.

Vojtech Kurka

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