Dockerfile制作基于Ubuntu的MySQL镜像
基于ubuntu18.04制作MySQL的docker镜像通过dockefile1.版本信息2.步骤通过dockefile1.版本信息镜像源:https://ogec0pyk.mirror.aliyuncs.com(阿里)Ubuntu:18.04MySQL:5.72.步骤编写DockerfileFROM ubuntuADD sources.list /etc/apt/A...
·
基于ubuntu18.04制作MySQL的docker镜像
通过dockefile
1.版本信息
- 镜像源:https://ogec0pyk.mirror.aliyuncs.com(阿里)
- Ubuntu:18.04
- MySQL:5.7
2.步骤
-
编写Dockerfile
FROM ubuntu #将sources.list复制到镜像下的/etc/apt/下面,修改镜像源地址 ADD sources.list /etc/apt/ #将run.sh脚本复制到镜像中(我这里随便找的路径) ADD run.sh /home/ #更新apt,因为更换了sources.list,所以比较快,使用官方镜像源在国外,速度特慢 RUN apt-get clean && apt-get update #安装MySQL RUN apt-get -y install mysql-server RUN chmod +x /home/run.sh EXPOSE 3306 CMD ["/home/run.sh"]
-
编写sources.list如下,使用的是阿里的,可在官网查找其他版本的
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
3.编写run.sh
#!/bin/bash
sed -i 's/127.0.0.1/0.0.0.0/' /etc/mysql/mysql.conf.d/mysqld.cnf
chown -R mysql:mysql /var/lib/mysql /var/run/mysqld
service mysql start
mysql -uroot -e "grant all privileges on *.* to 'root'@'%' identified WITH mysql_native_password by '123456';"
mysql -uroot -e "grant all privileges on *.* to 'root'@'localhost' identified WITH mysql_native_password by '123456';"
service mysql restart
/bin/bash
4.构建镜像
docker build -t lyfts:v4 .
镜像构建成功
- 启动容器
docker run -itd --name dfmysq4 -p 3323:3306 lyfts:v4
- 执行启动脚本,我将run.sh复制到/home目录下的
docker exec -i 容器id /home/run.sh
- 远程连接测试(MySQL已经启动成功)
到此结束,如有问题,请留言!!!
更多推荐
已为社区贡献1条内容
所有评论(0)