EmergencyEMERGENCY? Get 24/7 Help Now!

Playing with Percona XtraDB Cluster in Docker

 | June 30, 2015 |  Posted In: Docker, High-availability, MySQL, Percona XtraDB Cluster, Quality Assurance, XtraDB Cluster

PREVIOUS POST
NEXT POST

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
PREVIOUS POST
NEXT POST
Sveta Smirnova

Sveta joined Percona in 2015. Her main professional interests are problem solving, working with tricky issues, bugs, finding patterns that can solve typical issues quicker and teaching others how to deal with MySQL issues, bugs and gotchas effectively. Before joining Percona Sveta worked as a Support Engineer in the MySQL Bugs Analysis Support Group in MySQL AB-Sun-Oracle. She is the author of the book "MySQL Troubleshooting" and JSON UDF functions for MySQL.

4 Comments

  • 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 ?

  • 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@percona.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 ?

  • Tony, I am sorry for the delay in answer. I contacted with original maintainer of this Docker image asking to check how this issue can be fixed, but he is on travel now and we have to wait a little bit more when he is back. I will update you right after I have news.

  • 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”

Leave a Reply