大橙子网站建设,新征程启航

为企业提供网站建设、域名注册、服务器等服务

docker批量启动关闭所有容器的操作

docker中

成都网络公司-成都网站建设公司成都创新互联公司10多年经验成就非凡,专业从事成都做网站、成都网站设计,成都网页设计,成都网页制作,软文平台一元广告等。10多年来已成功提供全面的成都网站建设方案,打造行业特色的成都网站建设案例,建站热线:13518219792,我们期待您的来电!

启动所有的容器命令docker start $(docker ps -a | awk '{ print $1}' | tail -n +2)

docker中

关闭所有的容器命令docker stop $(docker ps -a | awk '{ print $1}' | tail -n +2)

补充:shell批量启动和删除docker容器,基于docker toolbox

停止容器stop.sh#!/bin/bashcontainerIDs="8f78b7e6995b beeae59c6f41 5305c3db3670 bffc551a6b96 61f0fc8b1dc4 8e85a3b7bfe3 d15c4d2dc546 2a3c4eb14584 5e98077acc3a 13bac087b83d"statusLived="live"statusdead="Dead"notExistContainer="None"retryCount=3function 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 donedone

说明:containerIDs里面是你已经建好的,docker容器这里为nginx

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

过程稍微慢了点,耐心等待。

停止容器成功。

启动容器#!/bin/bashcontainerIDs="8f78b7e6995b beeae59c6f41 5305c3db3670 bffc551a6b96 61f0fc8b1dc4 8e85a3b7bfe3 d15c4d2dc546 2a3c4eb14584 5e98077acc3a 13bac087b83d"statusLived="live"statusdead="Dead"notExistContainer="None"retryCount=3function 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 donedone

以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。如有错误或未考虑完全的地方,望不吝赐教。


名称栏目:docker批量启动关闭所有容器的操作
网址分享:http://dzwzjz.com/article/dsdes.html
在线咨询
服务热线
服务热线:028-86922220
TOP