详解docker 制作mysql镜像并自动安装脚本

本站所有内容来自互联网收集,仅供学习和交流,请勿用于商业用途。如有侵权、不妥之处,请第一时间联系我们删除!Q群:迪思分享

免费资源网 – https://freexyz.cn/

centos7环境下 一键制作mysql docker镜像,并安装

centos7环境下 一键制作mysql docker镜像,并安装

shell脚本内容如下:

#docker自动安装mysql echo -e “33[32m >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 默认安装参数: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 33[0m” echo -e “33[32m 端口:3309 33[0m” echo -e “33[32m 映射宿主机路径: /mysql 33[0m” echo -e “33[32m 密码:xxxxxx 33[0m” echo -e “33[32m 容器名称:mysql8 33[0m” echo -e “33[32m 开启binlog 33[0m” echo -e “33[32m 设置连接数1k 33[0m” echo -e “33[32m 设置连接超时断开24h 33[0m” echo -e “33[32m 设置使用4个cpu核心 33[0m” mkdir -p /mysql ### 1下载镜像 docker pull mysql if [ $? -eq 0 ] then echo -e “33[32m >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 1下载镜像 finish >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 33[0m” else echo -e “33[31m __________________________________ 1下载镜像 bad ,and EXIT 33[0m” exit 1 fi ###______________________________________________________________________________________________________ ### 创建 dockerfile rm -rf ./mymysql.yaml echo ### dockerfile 自定义mysql容器镜像 >> ./mymysql.yaml echo FROM mysql:latest >> ./mymysql.yaml echo #使用官方mysql镜像最新版 >> ./mymysql.yaml echo >> ./mymysql.yaml echo RUN echo “###” >> /etc/mysql/my.cnf >> ./mymysql.yaml echo >> ./mymysql.yaml echo RUN echo “log_bin = 1” >> /etc/mysql/my.cnf >> ./mymysql.yaml echo #开启binlog日志,存储在默认位置 >> ./mymysql.yaml echo >> ./mymysql.yaml echo RUN echo “max_connections = 1050” >> /etc/mysql/my.cnf >> ./mymysql.yaml echo RUN echo “mysqlx_max_connections = 1000” >> /etc/mysql/my.cnf >> ./mymysql.yaml echo #最大连接数 >> ./mymysql.yaml echo >> ./mymysql.yaml echo RUN echo “wait_timeout=86400” >> /etc/mysql/my.cnf >> ./mymysql.yaml echo RUN echo “interactive_timeout=86400” >> /etc/mysql/my.cnf >> ./mymysql.yaml echo #空闲断开时长,秒 >> ./mymysql.yaml echo >> ./mymysql.yaml echo RUN echo “innodb_read_io_threads=4” >> /etc/mysql/my.cnf >> ./mymysql.yaml echo RUN echo “innodb_write_io_threads=4” >> /etc/mysql/my.cnf >> ./mymysql.yaml echo #设置使用多核cpu,默认使用4核,根据cpu核心数设置 >> ./mymysql.yaml ###______________________________________________________________________________________________________ ###使用mymysql.yaml构建镜像mymysql:1 docker build -f ./mymysql.yaml -t “mymysql:1” . if [ $? -eq 0 ] then echo -e “33[32m >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> mymysql:1 镜像构建成功 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 33[0m” else echo -e “33[31m __________________________________ mymysql:1 镜像构建失败,and EXIT 33[0m” exit 1 fi ### 2创建容器 docker create -p 3309:3306 –restart=always –name mysql8 -v /mysql/mysql_08/log:/var/log/mysql -v /mysql/mysql_08/data:/var/lib/mysql -v /etc/localtime:/etc/localtime -e MYSQL_ROOT_PASSWORD=xxxxx -it mymysql:1 if [ $? -eq 0 ] then echo -e “33[32m >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 2创建容器 finish >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 33[0m” else echo -e “33[31m __________________________________ 2创建容器 bad ,and EXIT 33[0m” exit 1 fi ### 3启动容器 docker start mysql8 if [ $? -eq 0 ] then echo -e “33[32m >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 3启动容器 finish >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 33[0m” else echo -e “33[31m __________________________________ 3启动容器 bad ,and EXIT 33[0m” exit 1 fi ### 显示容器状态 echo -e “33[32m >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 显示已运行容器: 33[0m” docker ps
免费资源网 – https://freexyz.cn/


© 版权声明
THE END
★喜欢这篇文章吗?喜欢的话,麻烦动动手指支持一下!★
点赞10 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容