MySQL Replication using Docker

Vishal Raj
2 min readSep 3, 2019
Photo by frank mckenna on Unsplash

This article is about learning a bit of docker & containers, running MySQL in docker containers and setting up various types of MySQL replications using docker containers.

So what is Docker? Docker is an open source tool which allow you to package your application and all of its dependencies into a single package and run it ubiquitously without any discrimination based on hardware or host operating system. The docker containers are like a virtual machine, but are smaller in size and consume lesser resource. For details see https://www.docker.com/

So whats the benefit of running your application as docker container? Simple, it makes you application independent of the system where it will run. And the docker container packs in all the dependencies required by the application.

How to create docker container? In order to work with docker containers, you must have docker installed on the machine. Please see “Docker installation” for how to install docker based on the operating system of your machine.

One of many benefits of docker container is also that it makes horizontal scaling of an application very easy. Just spin up new docker containers of the application and you are set.

So why did I decide to do this? I wanted to learn about docker, containers, running applications in docker — specifically MySQL and how to setup the replication using docker containers.

There can be many ways of setting up MySQL replication, listed below are few

  1. Master to slave replication (stand-by replication)
  2. Master to master (multi-master) replication
  3. High availability replication (2 masters with 1 slave each of their own and masters are slave to each other)

So I decided to implement all of the above three replication schemes by my own and it took me almost a week (I wasn’t working on it continuously) but finally I got it done.

You can get it from — https://github.com/vishalraj82/MySQLReplDocker

If you have any query / suggestion / comments, please do so by dropping in your comment here. This repository code base is only for learning purpose only to be familiar with concepts of docker, containers, MySQL and replication and how to combine them all.

Note: I have added support for phpMyAdmin so that its easy to see what is happening inside of the MySQL nodes.

--

--