git clonehttps://github.com/DockerPool/mysql.git
cd mysql
docker build -t mysql .
创建一个主数据库容器
docker run -d-e REPLICATION_MASTER=true-e MYSQL_PASS="123456" -P --name mysql mysql
创建一个从数据库容器
docker run -d-e REPLICATION_SLAVE=true-e MYSQL_PASS="123456" -P --link mysql:mysql mysql
查看两个数据库容器是否运行
docker ps -a
1 2 3 4
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES c8e37ebffc15 mysql "/run.sh"22 hours ago Up 22 hours 0.0.0.0:32797->22/tcp, 0.0.0.0:32796->3306/tcp insane_rosalind ad7f81063654 mysql "/run.sh"22 hours ago Up 22 hours 0.0.0.0:32795->22/tcp, 0.0.0.0:32794->3306/tcp mysql
+--------------------+ | Database | +--------------------+ | information_schema | | hi_db | //I'M here,大家看到了吧 | mysql | | test | +--------------------+ 4 rows in set (0.00 sec)
mysql> use hi_db Database changed mysql> select * from hi_tb; //查看主服务器上新增的具体数据 +------+------+ | id | name | +------+------+ | 1 | bobu | +------+------+ 1 row in set (0.00 sec)