- Docker安装
>curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -OK>sudo add-apt-repository \"deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu \$(lsb_release -cs) \stable">sudo apt-get install docker-ce>sudo vi /etc/default/dockerDOCKER_OPTS="--registry-mirror=https://48h46wxj.mirror.aliyuncs.com">sudo usermod -aG docker username>sudo service docker restart
- MySQL镜像及容器创建
下载源GPG秘钥
>curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add ->sudo docker pull mysql (Using default tag:latest )
- 启动第一个mysql服务
>sudo docker run -d -p 3307:3306 --name mysql3306 \-v /opt/docker_v/mysql/3306/conf/3306.cnf:/etc/mysql/my.cnf \-v /opt/docker_v/mysql/3306/data:/var/lib/mysql/data/3306 \-v -e MYSQL_ROOT_PASSWORD=123456 \mysql:latest
2. 启动第二个mysql服务
>sudo docker run -d -p 127.0.0.1:3308:3306 --name mysql3307 \-v /opt/docker_v/mysql/3307/conf/3306.cnf:/etc/mysql/my.cnf \-v /opt/docker_v/mysql/3307/data:/var/lib/mysql \-e MYSQL_ROOT_PASSWORD=123456 \mysql:latest
3. 宿主机访问Docker容器:
$ mysql -h127.0.0.1 -P3308 -uroot
4. Docker MySQL 配置示例
# Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.## This program is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published by▽ the Free Software Foundation; version 2 of the License.## This program is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the# GNU General Public License for more details.## You should have received a copy of the GNU General Public License# along with this program; if not, write to the Free Software# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA## The MySQL Server configuration file.## For explanations see# http://dev.mysql.com/doc/mysql/en/server-system-variables.html[mysqld]pid-file = /var/run/mysqld/mysqld.pidsocket = /var/run/mysqld/mysqld.sockdatadir = /var/lib/mysql#log-error = /var/log/mysql/error.log# By default we only accept connections from localhost#bind-address = 127.0.0.1# Disabling symbolic-links is recommended to prevent assorted security riskssymbolic-links=0
5. MySQL 主从复制
mysql-master-server:IP:172.17.0.2]my.cnf[mysqld]... 其他配置server-id=1log-bin=mysql-bin #mysql-slave-server:IP:172.17.0.3my.cnf[mysqld]... 其他配置server-id=2mysql> change master to master_host='172.17.0.2', master_user='root', master_password='123456';mysql> start slave;mysql> show slave status\G;