docker pull daocloud.io/centos:latest
docker run -dit --privileged --name=centos7 daocloud.io/centos:latest /usr/sbin/init
docker exec -it centos7 /bin/bash
yum install -y wget
wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
yum -y install mysql57-community-release-el7-10.noarch.rpm
这里我安装就是8.0了 可以指定版本更吧
yum install -y mysql-server
systemctl start mysqld.service
[root@07c7d9259a1f /]# systemctl status mysqld.service
● mysqld.service - MySQL 8.0 database server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; disabled; vendor preset: disabled)
Active: active (running) since Mon 2019-10-21 10:19:04 UTC; 12s ago
Process: 219 ExecStartPost=/usr/libexec/mysql-check-upgrade (code=exited, status=0/SUCCESS)
Process: 133 ExecStartPre=/usr/libexec/mysql-prepare-db-dir mysqld.service (code=exited, status=0/SUCCESS)
Process: 95 ExecStartPre=/usr/libexec/mysql-check-socket (code=exited, status=0/SUCCESS)
Main PID: 173 (mysqld)
Status: "Server is operational"
Tasks: 39 (limit: 11869)
Memory: 732.1M
CGroup: /docker/07c7d9259a1f125895d069a29c8296f38677f5bedeadaf0572b20e44bd3ccac4/system.slice/mysqld.service
└─173 /usr/libexec/mysqld --basedir=/usr
Oct 21 10:19:01 07c7d9259a1f systemd[1]: Starting MySQL 8.0 database server...
Oct 21 10:19:04 07c7d9259a1f systemd[1]: Started MySQL 8.0 database server.
我的安装是没有root密码的
grep "password" /var/log/mysqld.log
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-RhsiIWxl-1571654300949)(C:\Users\Administrator\AppData\Roaming\Typora\typora-user-images\1571653689816.png)]
Mysql默认不允许远程登录,所以需要开启远程访问权限
可以先查看user表
select user,authentication_string,host from user;
默认都是localhost
update user set host = '%' where user = 'root';
此时root的host是所有都可以了
然后刷新修改,FLUSH PRIVILEGES;
docker commit -a "dedemao" -m "my mysql" centos7 dedemao/mysql
-a :提交的镜像作者;
-c :使用Dockerfile指令来创建镜像;
-m :提交时的说明文字;
-p :在commit时,将容器暂停。
docker run -dit --privileged -p 3310:3306 --name=mysql3310 dedemao/mysql /usr/sbin/init
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-o6rGul2E-1571654300957)(C:\Users\Administrator\AppData\Roaming\Typora\typora-user-images\1571654045840.png)]
要是mysql 没有启动则启动mysql
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-crR6SuNV-1571654300958)(C:\Users\Administrator\AppData\Roaming\Typora\typora-user-images\1571654120786.png)]
参考文档
https://blog.csdn.net/jason19905/article/details/81366202
https://www.cnblogs.com/goxcheer/p/9420460.html