How to perform data replication for DBs on multi-server Docker Container setup?

Setup Sketch

For setting up Disaster Recovery topology using docker, is it possible to perform data replication from one server to another without using any orchestration layer (swarm/Kubernetes)? Any way to setup MySQL Master-Master or Master-Slave on 2 server setup?

What I do NOT want:

  1. Data replication using shared disk space
  2. No third party tool/software
  3. No Swarm or Kubernetes

I understand that for a proper Disaster Recovery system, the standby system is recommended to be in a totally different region, and it's acceptable that there is delay in data replication. What I want to know is will the both docker containers be able to communicate with each other properly? Is there anything that needs to be configured? Or will they just communicate normally as it would have been without docker?


Two db servers, physically close to each other, will achieve the goal.

  • There will still be some lag from the Primary to the Replica, but probably less than 1ms.
  • The Replica won't start performing a replicated query until it has COMMITted on the Primary. (This is another mandatory lag.) As long as your writes affect only a small number of rows, this is also sub-millisecond or low-milliseconds.
  • If Master-Master, each is allowed to receive writes, and each is both a "master" and a "slave". However, I recommend only writing to one at a time; the other is simply a hot standby.
  • M-M is M-S already set up in both directions, hence allows for simplified failover.
  • Whether each db server is actually inside a Docker container should not matter.
  • But having two separate machines provides DR, whereas two Dockers in a single server does not protect against motherboard, disk, etc, failures.
  • The pieces for failover is part of the standard issue MySQL/MariaDB, but the performing a failover is still manual.
  • If one of the two machines fails, you need to take some non-trivial effort (and time) to rebuild the other machine.
  • Two machines in the same flood plain, earthquake fault, tornado alley, etc. -- For real DR, you need geographic separation. But that leads to latency between servers. Can't have everything!

See also Galera Cluster (shipped with MariaDB; or can be added to MySQL). With it, 3 "nodes", one per server, gives automatic failover and automatic repair.

As far as I know, Docker does not introduce any extra impediments. Maybe someone else will chime in. If there are multiple MySQL instances in multiple dockers, then there is an issue of getting the Port numbers separate.

PS. dba.stackoverflow.com is a better sight for MySQL/MariaDB questions.


Highly available services are never built with just two nodes. You need at least three, for split brain problem mitigation. In the geographically distributed case this problem is even more important than for physically co-located services; don't try to ignore it if you ever value your data and uptime. If you can't afford three nodes, better don't do any HA at all, or your attempts to get better service will make things worse instead.

Having established that, I suggest you to use Galera. It's multi-master replication built into modern MariaDB (a MySQL clone by the same author, a drop-in replacement). As expected, it requires three nodes, but of these only two must be full-blown servers, and a third one could be so called arbitration node (designed to be just tie-breaker in a quorum selection process).

So you make two containers containing data, and third machine to be an arbiter. Also you can make third node to be a full-blown server, but only use it to take database backups, so primary servers will not get choked at times when backup is running. And you then better set it to be a preferred SST source, so if one server restarts and needs SST, it'll not choke other one during SST process. It is important to have third node in the third place, not to be co-located with two primary servers, so it could be true tie-breaker.

I run such geographically distrubuted Galera setup, MariaDB instances are communicating via VPNs and it performs well.