Bash
public
Docker Container/Daemon Health Check
Share this script safely, inspect its metadata, and copy the exact command you need.
Ready to run
One-liner
curl -fsSL https://runny.sh/r/KDCTR4D6HBTB | bash
Current version: 1.1 · Updated by Godmode · 2026-09-07 02:38:59.084
At a glance
Script metadata
Readable before runnable
Preview
#!/usr/bin/env bash
# Docker Container / Daemon Health Check
# Read-only report of daemon reachability, container state, and disk use.
# Exit 0 if healthy, 1 if warnings, 2 if the daemon is down or a container is unhealthy.
# Hosted on Runny.sh. Review the script page before you run it.
set -u
status=0
warns=0
crits=0
note() {
printf '%s\n' "$*"
}
bump() {
case $1 in
crit)
crits=$((crits + 1))
status=2
;;
warn)
warns=$((warns + 1))
if [ "$status" -lt 1 ]; then
status=1
fi
;;
esac
}
note "=== Docker daemon and container health ==="
if ! command -v docker >/dev/null 2>&1; then
note "docker: CLI not found in PATH"
note "Result: CRITICAL"
exit 2
fi
note "Client: $(docker version --format '{{.Client.Version}}' 2>/dev/null || printf unknown)"
note ""
if ! docker info >/dev/null 2>&1; then
note "Daemon: unreachable"
note " Is the service running, and can this user talk to the socket?"
note "Result: CRITICAL"
exit 2
fi
server=$(docker info --format '{{.ServerVersion}}' 2>/dev/null || printf unknown)
driver=$(docker info --format '{{.Driver}}' 2>/dev/null || printf unknown)
root=$(docker info --format '{{.DockerRootDir}}' 2>/dev/null || printf unknown)
note "Daemon: ${server} driver ${driver}"
note "Root: ${root}"
note " OK"
note ""
running=$(docker ps -q 2>/dev/null | awk 'END { print NR }')
total=$(docker ps -aq 2>/dev/null | awk 'END { print NR }')
note "Containers: ${running} running / ${total} total"
unhealthy=$(docker ps --filter health=unhealthy --format '{{.Names}} {{.Status}}' 2>/dev/null || true)
if [ -n "${unhealthy}" ]; then
note "Unhealthy:"
printf '%s\n' "$unhealthy" | while IFS= read -r row; do
[ -n "$row" ] && note " - ${row}"
done
bump crit
else
note "Unhealthy: none"
fi
restarting=$(docker ps --filter status=restarting --format '{{.Names}} {{.Status}}' 2>/dev/null || true)
if [ -n "${restarting}" ]; then
note "Restarting:"
printf '%s\n' "$restarting" | while IFS= read -r row; do
[ -n "$row" ] && note " - ${row}"
done
bump crit
fi
dead=$(docker ps --filter status=dead --format '{{.Names}} {{.Status}}' 2>/dev/null || true)
if [ -n "${dead}" ]; then
note "Dead:"
printf '%s\n' "$dead" | while IFS= read -r row; do
[ -n "$row" ] && note " - ${row}"
done
bump crit
fi
exited_bad=$(docker ps -a --filter status=exited --format '{{.Names}} {{.Status}}' 2>/dev/null | awk '$0 ~ /Exited \([1-9]/ {print}' || true)
if [ -n "${exited_bad}" ]; then
note "Exited with error:"
count=0
while IFS= read -r row; do
[ -z "$row" ] && continue
count=$((count + 1))
if [ "$count" -le 8 ]; then
note " - ${row}"
fi
done <<EOF
${exited_bad}
EOF
if [ "$count" -gt 8 ]; then
note " ... $((count - 8)) more"
fi
bump warn
fi
note ""
note "Disk (docker system df):"
if docker system df >/dev/null 2>&1; then
docker system df | while IFS= read -r row; do
note " ${row}"
done
else
note " could not read docker system df"
bump warn
fi
note ""
if [ "$status" -eq 0 ]; then
note "Result: HEALTHY"
elif [ "$status" -eq 1 ]; then
note "Result: WARNING (${warns} check(s))"
else
note "Result: CRITICAL (${crits} critical, ${warns} warning)"
fi
exit "$status"
Raw endpointhttps://runny.sh/r/KDCTR4D6HBTB
See something unsafe?
Report this script
Tell us why it should come down. Anyone can also report a URL at /abuse.