Installing Percona XtraDB Cluster 5.6 with the Docker open-source engine

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.


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

Share this post

Comments (8)

  • Peter Zaitsev


    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.

    May 26, 2014 at 2:11 pm
  • Jericho Rivera


    I think Pipework [Software-defined networking for Linux Containers] would be the solution here, although I’ve read that there are other “hackish” ways to accomplish the job. Currently, Docker is in heavy development and I would assume that eventually it would be possible to explicitly set each node’s IP much like how vagrant does it with “private network”.

    May 27, 2014 at 4:18 am
  • Daniël van Eeden

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

    May 27, 2014 at 6:06 am
  • Jericho Rivera


    Thanks for pointing that out.

    Yes indeed, we can include the ADD option in the dockerfile like below:

    ADD ./percona.list /etc/apt/sources.list.d/percona.list
    ADD ./my.cnf /etc/my.cnf

    Assuming the file contents are correct, it would make the process of provisioning the node clusters much simpler.

    May 27, 2014 at 6:26 am
  • 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 :/

    June 20, 2014 at 6:46 pm
  • Jericho Rivera


    Its about showing the basics of setting up Percona XtraDB Cluster 5.6 on Docker, regarding whether this is the safest way to do container networking is beyond the scope of this blog IMHO. Readers may refer to Docker’s documentation for further reference here: (which is an advanced topic) and

    In hindsight, readers should be aware that this is only good for testing purposes and not fit (maybe not yet) for production use. I’ve also encountered some limitations with docker and on those rare occasions I tend to use Virtualbox. As I’ve also said before, docker is still heavily developed and there could still be changes on how the setup can be done.

    June 21, 2014 at 12:38 am
  • 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

    January 6, 2015 at 10:34 am
  • Joy

    Hello Jericho,

    Unable to execute below command , not getting keys

    RUN apt-key adv –keyserver –recv-keys 1C4CBDCDCD2EFD2A

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

    March 28, 2017 at 8:13 am

Comments are closed.