Skip to content
logo
Percona XtraDB Cluster
Running Percona XtraDB Cluster in a Docker Container
Initializing search
    percona/pxc-docs
    percona/pxc-docs
    • Home
      • Release notes index
      • Percona XtraDB Cluster 8.0.34-26 (2023-11-01)
      • Percona XtraDB Cluster 8.0.33-25 Update (2023-08-25)
      • Percona XtraDB Cluster 8.0.33-25 (2023-08-02)
      • Percona XtraDB Cluster 8.0.32-24.2 (2023-05-24)
      • Percona XtraDB Cluster 8.0.32-24 (2023-04-18)
      • Percona XtraDB Cluster 8.0.31-23.2 (2023-04-04)
      • Percona XtraDB Cluster 8.0.31-23 (2023-03-14)
      • Percona XtraDB Cluster 8.0.30-22.md (2022-12-28)
      • Percona XtraDB Cluster 8.0.29-21 (2022-09-12)
      • Percona XtraDB Cluster 8.0.28-19.1 (2022-07-19)
      • Percona XtraDB Cluster 8.0.27-18.1
      • Percona XtraDB Cluster 8.0.26-16.1
      • Percona XtraDB Cluster 8.0.25-15.1
      • Percona XtraDB Cluster 8.0.23-14.1
      • Percona XtraDB Cluster 8.0.22-13.1
      • Percona XtraDB Cluster 8.0.21-12.1
      • Percona XtraDB Cluster 8.0.20-11
      • Percona XtraDB Cluster 8.0.20-11.3
      • Percona XtraDB Cluster 8.0.20-11.2
      • Percona XtraDB Cluster 8.0.19-10
      • Percona XtraDB Cluster 8.0.18-9.3
      • About Percona XtraDB Cluster
      • Percona XtraDB Cluster limitations
      • Understand version numbers
      • High availability
      • Percona XtraDB Cluster strict mode
      • Online schema upgrade
      • Non-Blocking Operations (NBO) method for Online Scheme Upgrades (OSU)
      • Quickstart Guide for Percona XtraDB Cluster
      • Get started with Percona XtraDB Cluster
      • Install Percona XtraDB Cluster
      • Install Percona XtraDB Cluster on Debian or Ubuntu
      • Install Percona XtraDB Cluster on Red Hat Enterprise Linux and CentOS
      • Install Percona XtraDB Cluster from Binary Tarball
      • Compile and install from Source Code
      • Running Percona XtraDB Cluster in a Docker Container
      • Configure nodes for write-set replication
      • Bootstrap the first node
      • Add nodes to cluster
      • Verify replication
      • Upgrade Percona XtraDB Cluster
      • Restore a 5.7 backup to an 8.0 cluster
      • Security basics
      • Secure the network
      • Encrypt PXC traffic
      • Enable AppArmor
      • Enable SELinux
      • State snapshot transfer
      • Percona XtraBackup SST configuration
      • Restart the cluster nodes
      • Cluster failover
      • Monitor the cluster
      • Certification in Percona XtraDB Cluster
      • Percona XtraDB Cluster threading model
      • Understand GCache and Record-Set cache
      • GCache encryption and Write-Set cache encryption
      • Perfomance Schema instrumentation
      • Data at Rest Encryption
      • Crash recovery
      • Configure a cluster on Red Hat-based distributions
      • Configure a cluster on Debian or Ubuntu
      • Set up Galera arbitrator
      • How to set up a three-node cluster on a single box
      • How to set up a three-node cluster in EC2 environment
      • Load balancing with HAProxy
      • Load balance with ProxySQL
      • ProxySQL admin utilities
      • Set up a testing environment with ProxySQL
      • Index of wsrep status variables
      • Index of wsrep system variables
      • Index of wsrep_provider options
      • Index of files created by PXC
      • Telemetry on Percona XtraDB Cluster
      • Frequently asked questions
      • Glossary
      • Copyright and licensing information
      • Trademark policy

    Running Percona XtraDB Cluster in a Docker Container¶

    Docker images of Percona XtraDB Cluster are hosted publicly on Docker Hub at https://hub.docker.com/r/percona/percona-xtradb-cluster/.

    For more information about using Docker, see the Docker Docs. Make sure that you are using the latest version of Docker. The ones provided via apt and yum may be outdated and cause errors.

    We gather Telemetry data in the Percona packages and Docker images.

    Note

    By default, Docker pulls the image from Docker Hub if the image is not available locally.

    The image contains only the most essential binaries for Percona XtraDB Cluster to run. Some utilities included in a Percona Server for MySQL or MySQL installation might be missing from the Percona XtraDB Cluster Docker image.

    The following procedure describes how to set up a simple 3-node cluster for evaluation and testing purposes. Do not use these instructions in a production environment because the MySQL certificates generated in this procedure are self-signed. For a production environment, you should generate and store the certificates to be used by Docker.

    In this procedure, all of the nodes run Percona XtraDB Cluster 8.0 in separate containers on one host:

    1. Create a ~/pxc-docker-test/config directory.

    2. Create a custom.cnf file with the following contents, and place the file in the new directory:

      [mysqld]
      ssl-ca = /cert/ca.pem
      ssl-cert = /cert/server-cert.pem
      ssl-key = /cert/server-key.pem
      
      [client]
      ssl-ca = /cert/ca.pem
      ssl-cert = /cert/client-cert.pem
      ssl-key = /cert/client-key.pem
      
      [sst]
      encrypt = 4
      ssl-ca = /cert/ca.pem
      ssl-cert = /cert/server-cert.pem
      ssl-key = /cert/server-key.pem
      
    3. Create a cert directory and generate self-signed SSL certificates on the host node:

      $ mkdir -m 777 -p ~/pxc-docker-test/cert
      docker run --name pxc-cert --rm -v ~/pxc-docker-test/cert:/cert
      percona/percona-xtradb-cluster:8.0 mysql_ssl_rsa_setup -d /cert
      
    4. Create a Docker network:

      docker network create pxc-network
      
    5. Bootstrap the cluster (create the first node):

      docker run -d \
        -e MYSQL_ROOT_PASSWORD=test1234# \
        -e CLUSTER_NAME=pxc-cluster1 \
        --name=pxc-node1 \
        --net=pxc-network \
        -v ~/pxc-docker-test/cert:/cert \
        -v ~/pxc-docker-test/config:/etc/percona-xtradb-cluster.conf.d \
        percona/percona-xtradb-cluster:8.0
      
    6. Join the second node:

      docker run -d \
        -e MYSQL_ROOT_PASSWORD=test1234# \
        -e CLUSTER_NAME=pxc-cluster1 \
        -e CLUSTER_JOIN=pxc-node1 \
        --name=pxc-node2 \
        --net=pxc-network \
        -v ~/pxc-docker-test/cert:/cert \
        -v ~/pxc-docker-test/config:/etc/percona-xtradb-cluster.conf.d \
        percona/percona-xtradb-cluster:8.0
      
    7. Join the third node:

      docker run -d \
        -e MYSQL_ROOT_PASSWORD=test1234# \
        -e CLUSTER_NAME=pxc-cluster1 \
        -e CLUSTER_JOIN=pxc-node1 \
        --name=pxc-node3 \
        --net=pxc-network \
        -v ~/pxc-docker-test/cert:/cert \
        -v ~/pxc-docker-test/config:/etc/percona-xtradb-cluster.conf.d \
        percona/percona-xtradb-cluster:8.0
      

    To verify the cluster is available, do the following:

    1. Access the MySQL client. For example, on the first node:

      $ sudo docker exec -it pxc-node1 /usr/bin/mysql -uroot -ptest1234#
      
      Expected output
      mysql: [Warning] Using a password on the command line interface can be insecure.
      Welcome to the MySQL monitor.  Commands end with ; or \g.
      Your MySQL connection id is 12
      ...
      You are enforcing ssl connection via unix socket. Please consider
      switching ssl off as it does not make connection via unix socket
      any more secure
      
      mysql>
      
    2. View the wsrep status variables:

      mysql> show status like 'wsrep%';
      
      Expected output
      +------------------------------+-------------------------------------------------+
      | Variable_name                | Value                                           |
      +------------------------------+-------------------------------------------------+
      | wsrep_local_state_uuid       | 625318e2-9e1c-11e7-9d07-aee70d98d8ac            |
      ...
      | wsrep_local_state_comment    | Synced                                          |
      ...
      | wsrep_incoming_addresses     | 172.18.0.2:3306,172.18.0.3:3306,172.18.0.4:3306 |
      ...
      | wsrep_cluster_conf_id        | 3                                               |
      | wsrep_cluster_size           | 3                                               |
      | wsrep_cluster_state_uuid     | 625318e2-9e1c-11e7-9d07-aee70d98d8ac            |
      | wsrep_cluster_status         | Primary                                         |
      | wsrep_connected              | ON                                              |
      ...
      | wsrep_ready                  | ON                                              |
      +------------------------------+-------------------------------------------------+
      59 rows in set (0.02 sec)
      

    Contact us

    For free technical help, visit the Percona Community Forum.

    To report bugs or submit feature requests, open a JIRA ticket.

    For paid support and managed or consulting services , contact Percona Sales.


    Last update: 2023-11-01
    Percona LLC and/or its affiliates, © 2023
    Made with Material for MkDocs

    Cookie consent

    We use cookies to recognize your repeated visits and preferences, as well as to measure the effectiveness of our documentation and whether users find what they're searching for. With your consent, you're helping us to make our documentation better. Read more about Percona Cookie Policy.