一:offical manual url:
https://dev.mysql.com/doc/refman/5.7/en/docker-mysql-getting-started.html
1:download and setup:
1):Downloading a MySQL Server Docker Image
$ sudo docker pull mysql/mysql-server:tag
The tag is the label for the image version you want to pull (for example, 5.5, 5.6, 5.7, 8.0, or latest)
2): You can list downloaded Docker images with this command:
$ sudo docker images
3): Start a new Docker container for the MySQL Community Server with this command
$ sudo docker run --name=mysqltest -d mysql/mysql-server:tag
4): list of running containers when you run the docker ps command
$ sudo docker ps
5): Once initialization is finished, the command's output is going to contain the random password generated for the root use
$ sudo docker logs mysqltest
$ sudo docker logs mysqltest 2>&1 | grep GENERATED
6): Use the docker exec -it command to start a mysql client inside the Docker container you have started
$ sudo docker exec -it mysqltest mysql -uroot -p
7): Because the MYSQL_ONETIME_PASSWORD option is true by default, after you have connected a mysql client to the server, you must reset the server root password by issuing this statement:
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'password';
8): You can then run Linux commands inside the container. For example, to view contents in the server's data directory inside the container, use this command
# ls /var/lib/mysql
9): To stop the MySQL Server container we have created, use this command
$ sudo docker stop mysql1
10): To start the MySQL Server container again
$ sudo docker start mysql1
11): To stop and start again the MySQL Server container with a single command
$ sudo docker restart mysql1
12): To delete the MySQL container, stop it first, and then use the docker rm command
$ sudo docker stop mysql1 && sudo docker rm mysql1
13): Start a new MySQL 5.7 Docker container (named mysql57 in this example) with the old server data and configuration (with proper modifications if needed—see Section 2.11.1, “Upgrading MySQL”) that have been persisted on the host (by bind-mounting in this example). For the MySQL Community Server, run this command
$ sudo docker run --name=mysql57 \
--mount type=bind,src=/path-on-host-machine/my.cnf,dst=/etc/my.cnf \
--mount type=bind,src=/path-on-host-machine/datadir,dst=/var/lib/mysql \
-d mysql/mysql-server:5.7
二:Create MySql-server-5.7.24 Environment
1:Create network belong to mysql-server
sudo docker network create --subnet=172.21.0.0/16 b1
2: Create required directory
sudo mkdir -p /var/lib/mysql/{s1,s2,s3}
sudo mkdir -p /etc/mysql/{s1,s2,s3}
3: Touch and Edit /etc/mysql/s1/my.cnf,The s2 and s3 the smae as s1 ,except two lines is different example:
1):sudo vim /etc/mysql/s1/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
[mysqld]
user=root
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
port=3306
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
#log-error=/var/log/mysql/s1/mysqld.log
#pid-file=/var/run/mysqld/s1/mysqld.pid
# Group Replication
server_id = 1
gtid_mode = ON
enforce_gtid_consistency = ON
master_info_repository = TABLE
relay_log_info_repository = TABLE
binlog_checksum = NONE
log_slave_updates = ON
log_bin = binlog
binlog_format= ROW
transaction_write_set_extraction = XXHASH64
loose-group_replication_group_name = 'f69e3883-eb46-48a5-86fe-16a1498a5dd8'
loose-group_replication_start_on_boot = off
loose-group_replication_local_address = 'mysql1:33061'
loose-group_replication_group_seeds ='mysql1:33061,mysql2:33062,mysql3:33063'
loose-group_replication_bootstrap_group = off
#group_replication_allow_local_disjoint_gtids_join
2): sudo vim /etc/mysql/s2/my.cnf
server_id = 2
loose-group_replication_local_address = 'mysql2:33062'
3):sudo vim /etc/mysql/s3/my.cnf
server_id = 3
loose-group_replication_local_address = 'mysql3:33063'
三:Run mysql instance s1 s2 s3 on docker
1): sudo docker run --name=mysql1 -p 33061:3306 --name=mysql1 --hostname=mysql1 --net=b1 --ip=172.21.0.2 --add-host mysql2:172.21.0.3 --add-host mysql3:172.21.0.4 --volume=/etc/mysql/s1/:/etc/mysql --volume=/var/lib/mysql/s1:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=${PASSWORD} -d mysql/mysql-server:5.7
2): sudo docker run --name=mysql2 -p 33062:3306 --name=mysql2 --hostname=mysql2 --net=b1 --ip=172.21.0.3 --add-host mysql1:172.21.0.2 --add-host mysql3:172.21.0.4 --volume=/etc/mysql/s2:/etc/mysql --volume=/var/lib/mysql/s2:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=${PASSWORD} -d mysql/mysql-server:5.7
3):sudo docker run --name=mysql3 -p 33063:3306 --name=mysql3 --hostname=mysql3 --net=b1 --ip=172.21.0.4 --add-host mysql1:172.21.0.2 --add-host mysql2:172.21.0.3 --volume=/etc/mysql/s3:/etc/mysql --volume=/var/lib/mysql/s3:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=${PASSWORD} -d mysql/mysql-server:5.7
四: Setup MySql-server MGR Single-Primary Mode
Offical Manual url:
https://dev.mysql.com/doc/refman/5.7/en/group-replication-deploying-in-single-primary-mode.html