How to check if docker daemon is running?

后端 未结 7 779
庸人自扰
庸人自扰 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:39

    I made a little Script (Mac Osx) to ensure Docker is running by checking the exit code of docker stats.

    #!/bin/bash
    #Open Docker, only if is not running
    if (! docker stats --no-stream ); then
      # On Mac OS this would be the terminal command to launch Docker
      open /Applications/Docker.app
     #Wait until Docker daemon is running and has completed initialisation
    while (! docker stats --no-stream ); do
      # Docker takes a few seconds to initialize
      echo "Waiting for Docker to launch..."
      sleep 1
    done
    fi
    
    #Start the Container..
    

提交回复
热议问题