如何检查Docker是否正在运行 [英] How to check if docker is running or not
问题描述
我是Docker的新手。我正在为docker写一个简单的脚本。我需要检查docker是否正在运行。是否有命令来检查容器名称
I am new to docker. I am writing a simple script for docker. I need to check whether docker is running or not. Is there a command to check with container name
推荐答案
如果要查找特定的容器,则可以运行:
If you are looking for a specific container, you can run:
if [ "$( docker container inspect -f '{{.State.Running}}' $container_name )" == "true" ]; then ...
为避免发生崩溃循环并不断从显示中重启的容器出现问题可以通过检查 Status
字段来改进上述内容:
To avoid issues with a container that is in a crash loop and constantly restarting from showing that it's up, the above can be improved by checking the Status
field:
if [ "$( docker container inspect -f '{{.State.Status}}' $container_name )" == "running" ]; then ...
如果您想知道dockerd是否正在本地计算机上运行,并且安装了systemd后,您可以运行:
If you want to know if dockerd is running itself on the local machine and you have systemd installed, you can run:
systemctl show --property ActiveState docker
您还可以使用 docker info
或 docker版本连接到Docker code>,如果守护程序不可用,它们将出错。
You can also connect to docker with docker info
or docker version
and they will error out if the daemon is unavailable.
这篇关于如何检查Docker是否正在运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!