docker centos镜像安装mysql

1.拉取CentOs基础镜像
docker pull centos
2.启动容器,要加--privileged,不然使用systemctl会报错
docker run -idt --privileged centos init
3.进入容器
docker exec -it 83c2d9bc6aef /bin/bash

4.安装MySQL

1
2
3
4
5
6
7
yum -y install wget

wget http://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpm

yum -y install mysql57-community-release-el7-8.noarch.rpm

yum -y install mysql-community-server.x86_64

启动MySQL

systemctl start mysqld.service
systemctl enable mysqld.service

cat /var/log/mysqld.log | grep password

5.安装keepalived
yum -y install keepalived

6.登录MySQL,修改密码,授权远程访问。

7.导出容器快照到本地文件
docker export 83c2d9bc6aef -o keepalived.tar
8.将容器快照导入为镜像,下次就可以直接通过此镜像启动有MySQL和keepalived的容器
cat keepalived.tar | docker import - centos/keepalived