1.拉取CentOs基础镜像docker pull centos
2.启动容器,要加--privileged
,不然使用systemctl会报错docker run -idt --privileged centos init
3.进入容器docker exec -it 83c2d9bc6aef /bin/bash
4.安装MySQL
1 | yum -y install wget |
启动MySQL
systemctl start mysqld.service
systemctl enable mysqld.service
cat /var/log/mysqld.log | grep password
5.安装keepalivedyum -y install keepalived
6.登录MySQL
,修改密码,授权远程访问。
7.导出容器快照到本地文件docker export 83c2d9bc6aef -o keepalived.tar
8.将容器快照导入为镜像,下次就可以直接通过此镜像启动有MySQL和keepalived的容器cat keepalived.tar | docker import - centos/keepalived