拉取网易蜂巢的mysql-server:5.6
docker pull hub.c.163.com/nce2/mysql:5.6
创建mysql5.6容器 1master+3个slave
docker run --name mysql-master -d -P hub.c.163.com/nce2/mysql:5.6
docker run --name mysql-slave1 -d -P hub.c.163.com/nce2/mysql:5.6
docker run --name mysql-slave2 -d -P hub.c.163.com/nce2/mysql:5.6
docker run --name mysql-slave3 -d -P hub.c.163.com/nce2/mysql:5.6
验证容器状态
[root@bogon ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
907bbbf25d25 hub.c.163.com/nce2/mysql:5.6 "/run.sh" 5 minutes ago Up 5 minutes 3306/tcp mysql-slave3
a81df6c86808 hub.c.163.com/nce2/mysql:5.6 "/run.sh" 5 minutes ago Up 5 minutes 3306/tcp mysql-slave2
375eabd4c598 hub.c.163.com/nce2/mysql:5.6 "/run.sh" 5 minutes ago Up 5 minutes 3306/tcp mysql-slave1
1651d1cab219 hub.c.163.com/nce2/mysql:5.6 "/run.sh" 14 minutes ago Up 14 minutes 3306/tcp mysql-master
通过主机命令行进入master容器
docker exec -it mysql-master bash
[root@bogon ~]# docker exec -it mysql-master bash
root@1651d1cab219:/#
在master中创建一个数据库test_docker
root@1651d1cab219:/# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 4
Server version: 5.6.19-v1-log MySQL Community Server (GPL)
Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| #bak_database |
| mysql |
| performance_schema |
| test |
+--------------------+
5 rows in set (0.02 sec)
mysql> create database test_docker;
Query OK, 1 row affected (0.06 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| #bak_database |
| mysql |
| performance_schema |
| test |
| test_docker |
+--------------------+
6 rows in set (0.00 sec)
在slave1中创建一个数据库test_docker
[root@bogon ~]# docker exec -it mysql-slave bash
Error response from daemon: No such container: mysql-slave
[root@bogon ~]# docker exec -it mysql-slave1 bash