MySQL Master-Master docker sample config by mail@meo.bogliolo.name docker pull mysql/mysql-server:8.0 docker network create n1 for N in 1 2 do docker run -d --name=node$N --net=n1 --hostname=node$N \ -v $PWD/d$N:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=mypass \ mysql/mysql-server:8.0 \ --server-id=$N \ --log-bin='mysql-bin.log' \ --enforce-gtid-consistency='ON' \ --gtid-mode='ON' \ --auto_increment_increment=2 \ --auto_increment_increment=$N done sleep 5 for N in 1 2 do docker exec -it node$N mysql -uroot -pmypass \ -e "create user 'repl'@'%' identified by 'repass';" \ -e "GRANT REPLICATION SLAVE ON *.* TO repl@'%';" \ -e "reset master;" done docker exec -it node2 mysql -uroot -pmypass \ -e "change master to master_host='node1', master_port=3306, master_user='repl',master_password='repass', master_ssl=1, master_auto_position=1;" \ -e "start replica;" docker exec -it node1 mysql -uroot -pmypass \ -e "change master to master_host='node2', master_port=3306, master_user='repl',master_password='repass', master_ssl=1, master_auto_position=1;" \ -e "start replica;" -- Test replica docker logs node1 docker exec -it node1 mysql -uroot -pmypass -e "SELECT now();" docker exec -it node1 mysql -uroot -pmypass -e "SHOW REPLICA STATUS\G" docker exec -it node1 mysql -uroot -pmypass -e "SELECT * FROM performance_schema.replication_applier_status_by_worker;" docker exec -it node1 mysql -uroot -pmypass -e "create database sample;" docker exec -it node2 mysql -uroot -pmypass -e "show databases;" -- Test HA docker network disconnect n1 node2 docker kill node2 ... -- cleanup docker stop node1 node2 docker rm node1 node2 rm -rf d1 d2 docker network rm n1 -- docker rmi mysql/mysql-server:8.0 -- Other stuff... -e "flush privileges;" \ --restart on-failure -- Official documentation https://dev.mysql.com/blog-archive/setting-up-mysql-group-replication-with-mysql-docker-images/ https://dev.mysql.com/doc/refman/8.0/en/docker-mysql-getting-started.html