亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

docker批量啟動關(guān)閉所有容器的操作

 更新時間:2021年03月30日 09:54:34   作者:無限驕傲  
這篇文章主要介紹了docker批量啟動關(guān)閉所有容器的操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧

docker中

啟動所有的容器命令

docker start $(docker ps -a | awk '{ print $1}' | tail -n +2)

docker中

關(guān)閉所有的容器命令

docker stop $(docker ps -a | awk '{ print $1}' | tail -n +2)

補(bǔ)充:shell批量啟動和刪除docker容器,基于docker toolbox

停止容器

stop.sh
#!/bin/bash
containerIDs="8f78b7e6995b beeae59c6f41 5305c3db3670 bffc551a6b96 61f0fc8b1dc4 8e85a3b7bfe3 d15c4d2dc546 2a3c4eb14584 5e98077acc3a 13bac087b83d"
statusLived="live"
statusdead="Dead"
notExistContainer="None"
retryCount=3
function GetContainerStatus(){
 containerExist=$(docker ps -a | grep -i $1 | wc -l ) 
 if [ ${containerExist} -gt 0 ]
 then
 pid=$(docker stats --format "{{.PIDs}}" --no-stream $1 )
 if [ "${pid}" != "0" ]
  then 
  echo "${statusLived}"
 else
  echo "${statusdead}"
 fi
 else
 echo "${notExistContainer}" 
 fi
}
function StopContainer(){
 docker stop $1
}
for containerID in ${containerIDs}
 do
 for ((i=1;i<=${retryCount};i++))
 do
 status=$(GetContainerStatus ${containerID} )
 echo "Container ${containerID} status is ${status}"
 if [ "${status}" == ${statusdead} ]
 then
 echo "Container ${containerID} already stopped"
 break
 fi
 if [ "${status}" == ${notExistContainer} ]
 then
 echo "Container ${containerID} not existed"
 break
 fi
 if [ "${status}" == ${statusLived} ]
 then
  echo "Container ${containerID} is lived ,stop container"
  StopContainer ${containerID}
  verifyStatus=$(GetContainerStatus ${containerID} )
  if [ "${verifyStatus}" == ${statusdead} ]
  then
  echo "stop container ${containerID} success "
  break
  else
  echo "${i} retry stop container"
  StopContainer ${containerID}
  fi
 fi
 done
done

說明:containerIDs里面是你已經(jīng)建好的,docker容器這里為nginx

把stop.sh放在d:/nginx下面。

過程稍微慢了點(diǎn),耐心等待。

停止容器成功。

啟動容器

#!/bin/bash
containerIDs="8f78b7e6995b
 beeae59c6f41
 5305c3db3670
 bffc551a6b96
 61f0fc8b1dc4
 8e85a3b7bfe3
 d15c4d2dc546
 2a3c4eb14584
 5e98077acc3a
 13bac087b83d"
statusLived="live"
statusdead="Dead"
notExistContainer="None"
retryCount=3
function GetContainerStatus(){
 containerExist=$(docker ps -a | grep -i $1 | wc -l ) 
 if [ ${containerExist} -gt 0 ]
 then
 pid=$(docker stats --format "{{.PIDs}}" --no-stream $1 )
 if [ "${pid}" != "0" ]
  then 
  echo "${statusLived}"
 else
  echo "${statusdead}"
 fi
 else
 echo "${notExistContainer}" 
 fi
}
function StartContainer(){
 docker restart $1
}
for containerID in ${containerIDs}
 do
 for((i=1;i<=${retryCount};i++))
 do
 status=$(GetContainerStatus ${containerID} )
 echo "Container ${containerID} status is ${status}"
 if [ "${status}" == ${statusLived} ]
 then
 echo "Container ${containerID} already running"
 break
 fi
 if [ "${status}" == ${notExistContainer} ]
 then
 echo "Container ${containerID} not existed"
 break
 fi
 if [ "${status}" == ${statusdead} ]
 then
 echo "Container ${containerID} stopped ,start container"
 StartContainer ${containerID}
 verifyStatus=$(GetContainerStatus ${containerID} )
 if [ "${verifyStatus}" == ${statusLived} ]
  then
  echo "start container ${containerID} success "
  break
 else
  echo "${i} retry start container"
  StartContainer ${containerID}
 fi
 fi
 done
done

以上為個人經(jīng)驗(yàn),希望能給大家一個參考,也希望大家多多支持腳本之家。如有錯誤或未考慮完全的地方,望不吝賜教。

相關(guān)文章

  • 如何修改docker容器中MySQL的用戶密碼

    如何修改docker容器中MySQL的用戶密碼

    本文主要介紹了如何修改docker容器中MySQL的用戶密碼,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-04-04
  • Docker網(wǎng)絡(luò)原理及自定義網(wǎng)絡(luò)詳細(xì)解析

    Docker網(wǎng)絡(luò)原理及自定義網(wǎng)絡(luò)詳細(xì)解析

    一般使用自定義網(wǎng)絡(luò),自定義網(wǎng)絡(luò)使用network創(chuàng)建,創(chuàng)建時可以指定子網(wǎng)網(wǎng)段及網(wǎng)關(guān)等信息,在創(chuàng)建并啟動容器時指定使用的網(wǎng)絡(luò),今天通過本文給大家介紹Docker網(wǎng)絡(luò)原理及自定義網(wǎng)絡(luò)的相關(guān)知識,感興趣的朋友一起看看吧
    2021-05-05
  • deepin apt命令安裝最新版本的docker的方法

    deepin apt命令安裝最新版本的docker的方法

    這篇文章主要介紹了deepin apt命令安裝最新版本的docker的方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-09-09
  • 修改Docker容器內(nèi)文件的三種實(shí)現(xiàn)方式

    修改Docker容器內(nèi)文件的三種實(shí)現(xiàn)方式

    這篇文章主要介紹了修改Docker容器內(nèi)文件的三種實(shí)現(xiàn)方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-08-08
  • Docker數(shù)據(jù)卷和容器編排的使用

    Docker數(shù)據(jù)卷和容器編排的使用

    這篇文章主要介紹了Docker數(shù)據(jù)卷和容器編排的使用,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-07-07
  • Docker 解決獲取容器獲取的時間不是本地時間的問題

    Docker 解決獲取容器獲取的時間不是本地時間的問題

    這篇文章主要介紹了Docker 解決獲取容器獲取的時間不是本地時間的問題的相關(guān)資料,需要的朋友可以參考下
    2016-11-11
  • docker部署mysql8并設(shè)置可遠(yuǎn)程連接

    docker部署mysql8并設(shè)置可遠(yuǎn)程連接

    本文主要介紹了docker部署mysql8并設(shè)置可遠(yuǎn)程連接,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-07-07
  • Docker相關(guān)命令應(yīng)用匯總

    Docker相關(guān)命令應(yīng)用匯總

    如果各位看官熟悉 Git 和 GitHub ,可與 Docker 做個類比,可更加容易理解 Docker 和 Docker Hub 及兩者關(guān)系。
    2018-04-04
  • Docker-Compose實(shí)現(xiàn)Mysql主從的示例代碼

    Docker-Compose實(shí)現(xiàn)Mysql主從的示例代碼

    本文主要介紹了Docker-Compose實(shí)現(xiàn)Mysql主從的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-06-06
  • Docker?下MySQL數(shù)據(jù)庫的備份和恢復(fù)的操作方法

    Docker?下MySQL數(shù)據(jù)庫的備份和恢復(fù)的操作方法

    這篇文章主要介紹了Docker?下MySQL數(shù)據(jù)庫的備份和恢復(fù)操作方法,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2023-02-02

最新評論