In my previous post, I blogged about using Percona Server with Docker and have shown you how fast and easy it was to create a virtual environment with just a few commands.

This time I will be showing you how to setup a three-node Percona XtraDB Cluster (PXC) 5.6 on the Docker open-source engine. Just to review 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.”

In this case we will make use of a Dockerfile, think of this more like the Vagrantfile, it is a build script with a set of commands automating the creation of a new docker container.

For this case, we will use the following Dockerfile contents and use Ubuntu 12.04 instead of CentOS 6.5 as guest OS:

Create a my.cnf file and add the following:

Build an image from the Dockerfile we just created.

The ‘docker build’ command will create a new image from the Dockerfile build script. This will take a few minutes to complete. You can check if the new image was successfully built:

Now we will launch three containers with Percona XtraDB Cluster using the new docker image we have just created.

Check if the new containers were created:

Get relevant information from the container using ‘docker inspect’ command which by default will show a JSON-format output on the terminal. Since we only need to get the IP address for each container just run the following commands:

Take note of the IP address because we will need them later.

Do the same for dockerpxc2 and dockerpxc3 nodes. To attach to a container you need to run ‘docker attach {node_name}’ (eg # docker attach dockerpxc1). To exit without stopping the containers you need to hit CTRL+p/CTRL+q, otherwise an explicit ‘exit’ command on the prompt will drop you out of the container and stop the container as well, as much as possible we try to avoid this. Also make sure to edit wsrep_node_name and wsrep_node_address accordingly.

Bootstrapping the Cluster

Next step is to start the first node in the cluster, or bootstrapping.

After bootstrapping the first node, we can then prepare the first node for SST. That means we need to create the SST auth user, and in this case it is wsrep_ss_auth=pxcuser:pxcpass.

After adding the SST auth user on the first node the next step would be to start dockerpxc2 and dockerpxc3:

After starting all nodes, check the status of the entire cluster:

All three nodes are in the cluster!

Install net-tools to verify the default port for Galera.

Summary

I’ve shown you the following:

* Create a Dockerfile and my.cnf file
* Build a docker container using the created Dockerfile
* Made a few changes on some wsrep_ options on my.cnf
* Bootstrap the first node
* Start the other nodes of the cluster
* Check cluster status and confirmed all nodes are in the cluster

There are other ways to setup Docker with Percona XtraDB Cluster 5.6 such as using vagrant + docker which further automates the whole process or by using shell scripts, this article however shows you the basics of how to accomplish the same task.

On my next post, I will show how to setup Percona ClusterControl on another Docker container and adding this three-node PXC 5.6 cluster to it.

Read related posts here:

* Using MySQL Sandbox with Percona Server
* Testing Percona XtraDB Cluster with Vagrant
* Percona XtraDB Cluster: Setting up a simple cluster

8 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Peter Zaitsev

Jericho,

Nice! Though I wonder if it is possible to automate it to be more user friendly. As a user getting test cluster what I would do is to get back the cluster nodes IP (without messing with setting them in config) or might be even IP of HaProxy which is staying in front of the cluster.

Daniël van Eeden

You might want to use ADD in your dockerfile to add the percona.list and my.cnf files.

erkules

Isn’t it a very bad style to rely on the IP-address of the container?!
Most likley the IP is going to change after i.e. a restart. Propagating the usage of docker should not use any IP at all.
Also configuration is done *not* accessing the container :/

jb lezoray

First I just wanted to say you a big thank you for this tutorial, I’m a beginner with docker and it has been a great start point for me.

However, I’d pinpoint that it is mentioned a bit late in the article that the TTY must be detached with a ctrl-p ctrl-q.
Especially I’ve struggled with this command before realizing it:
for n in {1..3}; do docker run –name dockerpxc$n -i -t -d ubuntu_1204/percona:galera56 bash; done

Joy

Hello Jericho,

Unable to execute below command , not getting keys

RUN apt-key adv –keyserver keys.gnupg.net –recv-keys 1C4CBDCDCD2EFD2A

create this docker image using coreos Virtual machine , any one please let me know how this command we have executed ?