DZone
Database Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Database Zone > Docker Automatic MySQL Slave Propagation

Docker Automatic MySQL Slave Propagation

This article covers the steps needed to set up automated MySQL slave nodes using Docker.

Vadim Tkachenko user avatar by
Vadim Tkachenko
·
Jun. 24, 16 · Database Zone · Tutorial
Like (2)
Save
Tweet
2.90K Views

Join the DZone community and get the full member experience.

Join For Free

In this post, we'll discuss Docker automatic MySQL slave propagation for help with scaling.

In my previous posts on the Docker environment, I covered Percona XtraDB Cluster. Percona XtraDB Cluster can automatically scale by conveniently adding new nodes using the highly automated State Snapshot Transfer. State Snapshot Transfer allows a new node to copy data from an existing node (I still want to see how this is possible with MySQL Group Replication).

This is not the case with regular MySQL Replication. With MySQL Replication, the slave setup still requires manual steps (well, unless you've already scripted it for your environment). At least these are "simple" steps (ha!). Percona XtraBackup can setup replication with less work (see this link for details), but it still requires poking around and switching between servers.

However, nothing stops us from making it more automatic (similar to SST in Percona XtraDB Cluster), especially with Docker images. Why Docker? Because Docker provides a highly controlled environment where we can orchestrate how scripts get executed. Severalnines provides a great intro into MySQL with Docker.

There are a few more components for this setup:

Before jumping to my solution, I should point to some work in this area by Joyent.

I propose my image with sources on GitHub.

First, we need to start a master node:

docker run-d-p3306:3306--net=replicaset_net

--name=replicaset_master

-eMYSQL_ROOT_PASSWORD=Theistareyk

perconalab/ps-master-slave--innodb-buffer-pool-size=2G

I assume that we've created the network replicaset_net already, either bridge or overlay.

You can create a slave by pointing to the master container:

docker run-d-p3306--net=replicaset_net

--name=replicaset_slave1

-eMYSQL_ROOT_PASSWORD=Theistareyk

-eMASTER_HOST=replicaset_master

perconalab/ps-master-slave--innodb-buffer-pool-size=2G

The started node will automatically connect to MASTER_HOST, copy the data and perform all the steps needed to start the slave.

You can even copy data from a running slave, instead of the master, like this:

docker run-d-p3306--net=replicaset_net

--name=replicaset_slave2

-eMYSQL_ROOT_PASSWORD=Theistareyk

-eMASTER_HOST=replicaset_master

-eSLAVE_HOST=replicaset_slave1

perconalab/ps-master-slave--innodb-buffer-pool-size=2G


This node will copy data from SLAVE_HOST, but then will point itself to MASTER_HOST.

Docker Network lets you use container names "replicaset_master" and "replicaset_slave1" instead of IP addresses, which is very convenient.

As the result of above, we have one master and two slaves running. We can start as many slave nodes as needed.

Please remember, this is more proof-of-concept than "production ready" images, but it gives a good direction for implementation.

Docker (software) MySQL

Published at DZone with permission of Vadim Tkachenko, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • When Microservices Are a Bad Idea
  • What to Know About Python and Why Its the Most Popular Today
  • Java Class Loading: Performance Impact
  • DZone's Article Submission Guidelines

Comments

Database Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo