DEV Community

Vishal Raj
Vishal Raj

Posted on

Learn MySQL Replication with Docker

MySQL is one of the most popular open source RDBMS used by an number of web applications for various purpose. 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, application containerization tool which allow you to package your application and all of its required 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. So an application developed in Linux can be run on Windows / Mac.

How to create docker container? In order to work with docker containers, you must have docker engine installed on the host 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 experiment with docker, containers, running applications inside docker — specifically MySQL and how to setup the replication using docker containers. There can be many ways of setting up MySQL replication, but I implemented the following replication schemes

  • Master to slave replication (stand-by replication)
  • Master to master (multi-master) replication

So I decided to implement all of the above 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.

Original article - https://vishalraj.blog/learn-mysql-replication-with-docker/

Top comments (0)