使用Shell脚本批量启停Docker服务

2020-06-17 06:38:19易采站长站整理

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

Python调用脚本

Python示例脚本如下所示:


import paramiko
def StartContainer(svr,port,user,pwd):
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(svr,port=port, username=user, password=pwd,timeout=5)
client.exec_command("cd /home/TestCode/ && bash startContainer.sh")
def StopContainer(svr,port,user,pwd):
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(svr, port=port, username=user, password=pwd, timeout=5)
client.exec_command("cd /home/TestCode/ && bash stopContainer.sh ")

总结

以上所述是小编给大家介绍的使用Shell脚本批量启停Docker服务,希望对大家有所帮助!

您可能感兴趣的文章:docker.service启动失败:Unit not found的原因及解决办法CentOS7 安装docker 解决启动不了的问题Docker容器的创建、启动、和停止的方法