Like any good, thus lazy, engineer I don’t like to start things manually. Creating directories, configuration files, specify paths, ports via command line is too boring. I wrote already how I survive in case when I need to start MySQL server (here). There is also the MySQL Sandbox which can be used for the same purpose.

Playing with Percona XtraDB Cluster in DockerBut what to do if you want to start Percona XtraDB Cluster this way? Fortunately we, at Percona, have engineers who created automation solution for starting PXC. This solution uses Docker. To explore it you need:

  1. Clone the pxc-docker repository:
    git clone https://github.com/percona/pxc-docker
  2. Install Docker Compose as described here
  3. cd pxc-docker/docker-bld
  4. Follow instructions from the README file:

    a) ./docker-gen.sh 5.6    (docker-gen.sh takes a PXC branch as argument, 5.6 is default, and it looks for it on github.com/percona/percona-xtradb-cluster)

    b) Optional: docker-compose build (if you see it is not updating with changes).

    c) docker-compose scale bootstrap=1 members=2 for a 3 node cluster

  5. Check which ports assigned to containers:

    Now you can connect to MySQL clients as usual:
  6. To change MySQL options either pass it as a mount at runtime with something like volume: /tmp/my.cnf:/etc/my.cnf in docker-compose.yml or connect to container’s bash (docker exec -i -t container_name /bin/bash), then change my.cnf and run docker restart container_name

Notes.

  • If you don’t want to build use ready-to-use images
  • If you don’t want to run Docker Compose as root user add yourself to docker group
7 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Tony Liu

Hi Sveta,

I got error like this:

docker-bld$ docker-machine ssh default
## .
## ## ## ==
## ## ## ## ## ===
/”””””””””””””””””\___/ ===
~~~ {~~ ~~~~ ~~~ ~~~~ ~~~ ~ / ===- ~~~
\______ o __/
\ \ __/
\____\_______/
_ _ ____ _ _
| |__ ___ ___ | |_|___ \ __| | ___ ___| | _____ _ __
| ‘_ \ / _ \ / _ \| __| __) / _ |/ _ \ / __| |/ / _ \ '__|
| |_) | (_) | (_) | |_ / __/ (_| | (_) | (__| < __/ |
|_.__/ \___/ \___/ \__|_____\__,_|\___/ \___|_|\_\___|_|
Boot2Docker version 1.9.1, build master : cef800b - Fri Nov 20 19:33:59 UTC 2015
Docker version 1.9.1, build a34a1d5
docker@default:~$ ls
log.log
docker@default:~$ ls /
bin/ dev/ etc/ home/ init lib/ lib64 linuxrc mnt/ opt/ proc/ root/ run/ sbin/ sys/ tmp usr/ var/
docker@default:~$ exit
docker-bld$ docker-compose scale bootstrap=1 members=2
WARNING: The RANDOM variable is not set. Defaulting to a blank string.
ERROR: Couldn't connect to Docker daemon - you might need to run
docker-machine start default`.

Would you please give some advice here ?

Tony Liu

Please ignore previous comment.
Here is the output of
$docker-compose build

WARNING: The RANDOM variable is not set. Defaulting to a blank string.
Building bootstrap
Step 0 : FROM centos:centos7
—> ce20c473cd8a
Step 1 : MAINTAINER Raghavendra Prabhu raghavendra.prabhu.com
—> Using cache
—> 99ffa239711d
Step 2 : RUN curl -s https://github.com/percona/percona-repositories/blob/master/rpm/percona-release.repo > /etc/yum.repos.d/percona-dev.repo
—> Using cache
—> 9633aa93213c
Step 3 : RUN yum install -y http://epel.check-update.co.uk/7/x86_64/e/epel-release-7-5.noarch.rpm
—> Running in a57b46a572a8
Loaded plugins: fastestmirror

File contains no section headers.
file: file:///etc/yum.repos.d/percona-dev.repo, line: 4
‘\n’
ERROR: Service ‘bootstrap’ failed to build: The command ‘/bin/sh -c yum install -y http://epel.check-update.co.uk/7/x86_64/e/epel-release-7-5.noarch.rpm‘ returned a non-zero code: 1

The “http://jenkins.percona.com/dev-repo/percona-dev.repo” in Dockfile is no longer valid, how to fix it ?

Shahriyar Rzayev

First of all, I should note that, could run this only with CentOS 7.
But there were some errors and I want to share workarounds.

Change dev-repo link as it was changed:

http://jenkins.percona.com/yum-repo/percona-dev.repo

New should be similar to:
vim docker-gen.sh
RUN curl -s http://jenkins.percona.com/yum-repo/percona-dev.repo > /etc/yum.repos.d/percona-dev.repo

Also change make command:

from “RUN make -j$numcp” to “RUN make -j 1”

Fred Ward

I’ve changed the pxc_strict_mode to permissive in wsrep.cnf and even added it to the node.cnf file to no avail. It persists even if I use mysqld restart –pxc_strict_mode=PERMISSIVE. Any thoughts?

Fred Ward

Actually, I figured it out. You have to stipulate “configs” secion in the yaml.

configs:
– source: my_config
target: /etc/mysql/my.cnf
uid: ‘1000’
gid: ‘1000’
mode: 0444
– source: wsrep_config
target: /etc/mysql/percona-xtradb-cluster.conf.d/wsrep.cnf
uid: ‘1000’
gid: ‘1000’
mode: 0444

configs:
my_config:
file: /root/backup/mysql/my.cnf
wsrep_config:
file: /root/backup/mysql/percona-xtradb-cluster.conf.d/wsrep.cnf

In the my.cnf just add:

[mysqld]
pxc_strict_mode=PERMISSIVE

I added the wsrep config as well in order to ensure that the strict mode setting located in that file did not override the my.cnf setting.