千家信息网

docker制作mysql镜像并自动安装脚本怎么写

发表于:2024-12-03 作者:千家信息网编辑
千家信息网最后更新 2024年12月03日,本文小编为大家详细介绍"docker制作mysql镜像并自动安装脚本怎么写",内容详细,步骤清晰,细节处理妥当,希望这篇"docker制作mysql镜像并自动安装脚本怎么写"文章能帮助大家解决疑惑,下
千家信息网最后更新 2024年12月03日docker制作mysql镜像并自动安装脚本怎么写

本文小编为大家详细介绍"docker制作mysql镜像并自动安装脚本怎么写",内容详细,步骤清晰,细节处理妥当,希望这篇"docker制作mysql镜像并自动安装脚本怎么写"文章能帮助大家解决疑惑,下面跟着小编的思路慢慢深入,一起来学习新知识吧。

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

shell脚本内容如下:

#docker自动安装mysqlecho -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 mysqlif [ $? -eq 0 ]    then         echo -e "\033[32m '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 1下载镜像 finish >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>' \033[0m"    else         echo -e "\033[31m '__________________________________  1下载镜像 bad ,and EXIT' \033[0m"        exit 1fi###______________________________________________________________________________________________________### 创建 dockerfilerm -rf ./mymysql.yamlecho '### dockerfile 自定义mysql容器镜像' >> ./mymysql.yamlecho 'FROM mysql:latest' >> ./mymysql.yamlecho '#使用官方mysql镜像最新版' >> ./mymysql.yamlecho '' >> ./mymysql.yamlecho 'RUN echo "###" >> /etc/mysql/my.cnf' >> ./mymysql.yamlecho '' >> ./mymysql.yamlecho 'RUN echo "log_bin = 1" >> /etc/mysql/my.cnf' >> ./mymysql.yamlecho '#开启binlog日志,存储在默认位置' >> ./mymysql.yamlecho '' >> ./mymysql.yamlecho 'RUN echo "max_connections = 1050" >> /etc/mysql/my.cnf' >> ./mymysql.yamlecho 'RUN echo "mysqlx_max_connections = 1000" >> /etc/mysql/my.cnf' >> ./mymysql.yamlecho '#最大连接数' >> ./mymysql.yamlecho '' >> ./mymysql.yamlecho 'RUN echo "wait_timeout=86400" >> /etc/mysql/my.cnf' >> ./mymysql.yamlecho 'RUN echo "interactive_timeout=86400" >> /etc/mysql/my.cnf' >> ./mymysql.yamlecho '#空闲断开时长,秒' >> ./mymysql.yamlecho '' >> ./mymysql.yamlecho 'RUN echo "innodb_read_io_threads=4" >> /etc/mysql/my.cnf' >> ./mymysql.yamlecho 'RUN echo "innodb_write_io_threads=4" >> /etc/mysql/my.cnf' >> ./mymysql.yamlecho '#设置使用多核cpu,默认使用4核,根据cpu核心数设置' >> ./mymysql.yaml###______________________________________________________________________________________________________###使用mymysql.yaml构建镜像mymysql:1docker 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 1fi### 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:1if [ $? -eq 0 ]    then         echo -e "\033[32m '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>  2创建容器 finish >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>' \033[0m"    else         echo -e "\033[31m '__________________________________  2创建容器 bad ,and EXIT' \033[0m"        exit 1fi### 3启动容器docker start mysql8if [ $? -eq 0 ]    then         echo -e "\033[32m '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 3启动容器 finish >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>' \033[0m"    else         echo -e "\033[31m '__________________________________  3启动容器 bad ,and EXIT' \033[0m"        exit 1fi### 显示容器状态echo -e "\033[32m '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 显示已运行容器:' \033[0m"docker ps

读到这里,这篇"docker制作mysql镜像并自动安装脚本怎么写"文章已经介绍完毕,想要掌握这篇文章的知识点还需要大家自己动手实践使用过才能领会,如果想了解更多相关内容的文章,欢迎关注行业资讯频道。

0