赞
踩
编写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
docker exec -i 容器id /home/run.sh
到此结束,如有问题,请留言!!!
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。