如何检查docker daemon是否正在运行? [英] How to check if docker daemon is running?

查看:902
本文介绍了如何检查docker daemon是否正在运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个bash实用程序脚本,以检查我的服务器中是否正在运行docker守护程序. 除了运行这样的代码之外,还有没有更好的方法来检查docker守护进程是否正在我的服务器中运行?

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 server other than running a code like this?

ps -ef | grep docker
root      1250     1  0 13:28 ?        00:00:04 /usr/bin/dockerd --selinux-enabled
root      1598  1250  0 13:28 ?        00:00:00 docker-containerd -l unix:///var/run/docker/libcontainerd/docker-containerd.sock --shim docker-containerd-shim --metrics-interval=0 --start-timeout 2m --state-dir /var/run/docker/libcontainerd/containerd --runtime docker-runc
root     10997 10916  0 19:47 pts/0    00:00:00 grep --color=auto docker

我想创建一个bash shell脚本,该脚本将检查我的docker守护进程是否正在运行.如果它正在运行,则不执行任何操作,如果未运行,则启动docker守护程序.

I would like to create a bash shell script that will check if my docker daemon is running. If it is running then do nothing but if it is not then have the docker daemon started.

我的伪代码是这样的.我正在考虑解析ps -ef的输出,但是我只是想知道是否有一种更有效的方式来进行伪代码.

My pseudocode is something like this. I am thinking of parsing the output of my ps -ef but I just would like to know if there is a more efficient way of doing my pseudocode.

如果(泊坞窗未运行)

if(docker is not running)

          run docker

结束

P.S. 我不是Linux专家,我只需要在自己的环境中执行此实用程序即可.

P.S. I am no linux expert and I just need to do this utility on my own environment.

推荐答案

几乎所有Linux系统上都有一个名为pgrep的实用程序.

You have a utility called pgrep on almost all the Linux systems.

您可以这样做:

pgrep -f docker > /dev/null || echo "starting docker"

echo命令替换为docker启动命令.

Replace the echo command with your docker starting command.

这篇关于如何检查docker daemon是否正在运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆