您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
本文小编为大家详细介绍“docker制作mysql镜像并自动安装脚本怎么写”,内容详细,步骤清晰,细节处理妥当,希望这篇“docker制作mysql镜像并自动安装脚本怎么写”文章能帮助大家解决疑惑,下面跟着小编的思路慢慢深入,一起来学习新知识吧。
shell脚本内容如下:
#docker自动安装mysql echo -e "\033[32m '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 默认安装参数: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>' \033[0m" echo -e "\033[32m '端口:3309' \033[0m" echo -e "\033[32m '映射宿主机路径: /mysql' \033[0m" echo -e "\033[32m '密码:xxxxxx' \033[0m" echo -e "\033[32m '容器名称:mysql8' \033[0m" echo -e "\033[32m '开启binlog' \033[0m" echo -e "\033[32m '设置连接数1k' \033[0m" echo -e "\033[32m '设置连接超时断开24h' \033[0m" echo -e "\033[32m '设置使用4个cpu核心' \033[0m" mkdir -p /mysql ### 1下载镜像 docker pull mysql if [ $? -eq 0 ] then echo -e "\033[32m '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 1下载镜像 finish >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>' \033[0m" else echo -e "\033[31m '__________________________________ 1下载镜像 bad ,and EXIT' \033[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 "\033[32m '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> mymysql:1 镜像构建成功 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>' \033[0m" else echo -e "\033[31m '__________________________________ mymysql:1 镜像构建失败,and EXIT' \033[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 "\033[32m '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 2创建容器 finish >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>' \033[0m" else echo -e "\033[31m '__________________________________ 2创建容器 bad ,and EXIT' \033[0m" exit 1 fi ### 3启动容器 docker start mysql8 if [ $? -eq 0 ] then echo -e "\033[32m '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 3启动容器 finish >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>' \033[0m" else echo -e "\033[31m '__________________________________ 3启动容器 bad ,and EXIT' \033[0m" exit 1 fi ### 显示容器状态 echo -e "\033[32m '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 显示已运行容器:' \033[0m" docker ps
读到这里,这篇“docker制作mysql镜像并自动安装脚本怎么写”文章已经介绍完毕,想要掌握这篇文章的知识点还需要大家自己动手实践使用过才能领会,如果想了解更多相关内容的文章,欢迎关注亿速云行业资讯频道。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。