您好,登錄后才能下訂單哦!
本文小編為大家詳細介紹“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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。