(1)拉取centos7官方镜像
docker pull centos:centos7
(2)以超级管理员启动centos
docker run -itd -p 5000:22 --name keepalived-master --privileged=true centos:centos7 /usr/sbin/init
#以一般用户启动:docker run -itd -p 5000:22 --name centos7 --privileged=true centos:centos7 /bin/bash
(3)安装keepalived
#安装网络包(需要使用ifconfig和ping命令)
yum install net-tools
#安装vim
yum install vim
#安装keepalived环境依赖
yum install -y gcc openssl-devel popt-devel
#安装keepalived
yum install keepalived
启动
systemctl start keepalived
(4)安装mysql
yum install -y wget
wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
rpm -ivh mysql-community-release-el7-5.noarch.rpm
yum update
yum install mysql-server
注:这种方式安装会默认安装mysql5.6版本,若是要安装5.7版本,需要修改配置文件。
可参考下面的方法:
【linux环境安装mysql5.7 - 仅此而已-远方 - 博客园】
启动
systemctl start mysql
装好mysql和keepalived之后,可以将使用下面的命令将容器打成docker镜像。
docker commit -a "作者" -m "说明文" 【容器ID】 【镜像名:tag】
如:docker commit -a "pjq" -m "master" e78728befa1b mysql-keepalived:v1