Get the App
SLTechnology News&Howtos  ›  Servers  › 

Use Shell script to start and stop Docker service in batch

Shulou Source: shulou.com Published: 2022-06-02 04:07:35 10月30日 Update

Recently, you often need to start or stop docker manually in daily testing, so you decide to write a Shell script instead of manual operation. In addition, this script can also be called remotely through the Python script, as shown below:

At present, the script is to write Container ID in the script, of course, you can also pass parameters to the script to control, you can modify it.

Start docker

The details of the startup script are as follows:

#! / bin/bashcontainerIDs= "ad3e4d7fc407 a228730a915f ad3e4d7fc4099" statusLived= "live" statusdead= "Dead" notExistContainer= "None" retryCount=3function GetContainerStatus () {containerExist=$ (sudo docker ps-a | grep-I $1 | wc-l) if [${containerExist}-gt 0] then pid=$ (sudo docker stats-- format "{{.PIDs}"-- no-stream $1) if ["${pid}"! = "0"] then echo "${statusLived}" else echo "${statusdead} "fi else echo" ${notExistContainer} "fi} function StartContainer () {sudo docker restart $1} for containerID in ${containerIDs} do for ((iTun1) I

Tags: Scripts that can be passed service manual manual sample help control modification testing Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Apple MariaDB Docker Shulou Technology