日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學(xué)無先后,達(dá)者為師

網(wǎng)站首頁 編程語言 正文

使用shell腳本快速登錄容器的實(shí)現(xiàn)步驟_linux shell

作者:執(zhí)劍問道 ? 更新時間: 2022-10-18 編程語言

當(dāng)我已經(jīng)安裝好容器后,例如mysql,Redis等,想要快捷登錄時,可以用shell腳本一鍵登錄。

首先要寫好要用的腳本,例如登錄mysql容器后,我們要輸入mysql-u root -p123456。我們把它直接寫入sqlpasswd.sh中。

然后再把他復(fù)制到mysql容器里,docker cp sqlpasswd.sh mysql-test:/。因?yàn)檫M(jìn)入容器后會開另外一個shell來執(zhí)行這個腳本。如下,我們在后面接上bash xx.sh,可在容器中執(zhí)行。

效果圖:

虛擬機(jī)腳本代碼:

#!/bin/bash
read -p "選擇要進(jìn)入的服務(wù):
1.mysql:
2.redis:
3.nginx:" n

if [ $n == 1 ]
then
        echo "正在登錄mysql"
        docker exec -it mysql-test bash sqlpasswd.sh

fi

if [ $n == 2 ]
then
        echo "正在登錄redis"
        docker exec -it redis-test bash redis-cli.sh
fi

if [ $n == 3 ]
then
        echo "正在登錄nginx"
        docker exec -it nginx-test bash
fi

sqlpasswd.sh:(記得要從虛擬機(jī)復(fù)制到容器中:docker cp sqlpasswd.sh mysql-test:/)

#!/bin/bash
mysql -u root -p123456

原文鏈接:https://blog.csdn.net/weixin_45881896/article/details/126063620

欄目分類
最近更新