How to check if docker daemon is running?

后端 未结 7 798
庸人自扰
庸人自扰 2020-12-15 04:31

I am trying to create a bash utility script to check if a docker daemon is running in my server. Is there a better way of checking if the docker daemon is running in my serv

7条回答
  •  北荒
    北荒 (楼主)
    2020-12-15 04:55

    The following works on macOS and on Windows if git bash is installed. On macOS open /Applications/Docker.app would start the docker deamon. Haven't seen anything similar for Windows however.

    ## check docker is running at all
    ## based on https://stackoverflow.com/questions/22009364/is-there-a-try-catch-command-in-bash
    {
      ## will throw an error if the docker daemon is not running and jump
      ## to the next code chunk     
      docker ps -q
    } || {
      echo "Docker is not running. Please start docker on your computer"
      echo "When docker has finished starting up press [ENTER} to continue"
      read
    }
    

提交回复
热议问题