Docker Compose for MySQL High Availablity

Another utility project: Just paste here:


One-command docker compose configuration to set up a MySQL master-slave replication with HA/Failover support.
It’s a simplified version inspired by Github:

Putting the flow together:
– The orchestrator nodes detect failures.
– The orchestrator/raft leader kicks off a recovery. A new primary gets promoted.
– orchestrator/raft advertises the primary change to all raft cluster nodes.
– Each orchestrator/raft member receives a leader change notification. They each update the local Consul’s KV store with the identity of the new primary.
– Each GLB/HAProxy has consul-template running, which observes the change in Consul’s KV store, and reconfigures and reloads HAProxy.
– Client traffic gets redirected to the new primary.

More info:


  • MySQL 8.0
  • Orchestrator 3.1.4
  • Consul 1.8
  • Consul Template 0.25.1
  • HAProxy 2.0


Component Address External Address
MySQL localhost:13306 localhost:13307 localhost:13308
Orchestrator localhost:14000
Consul localhost:14001
Consul Template N/A N/A
HAProxy localhost:3306 localhost:8000

Open http://localhost:14000 to visit Orchestrator.

Connect to MySQL via HAProxy:

Verify cluster failover with:

Leave a Reply

Your email address will not be published. Required fields are marked *