Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Bash Script for Nagios to Check Status of Docker Container
# Author: Erik Kristensen
# Email:
# License: MIT
# Nagios Usage: check_nrpe!check_docker_container!_container_id_
# Usage: ./ _container_id_
# The script checks if a container is running.
# OK - running
# WARNING - container is ghosted
# CRITICAL - container is stopped
# UNKNOWN - does not exist
RUNNING=$(docker inspect --format="{{ .State.Running }}" $CONTAINER 2> /dev/null)
if [ $? -eq 1 ]; then
echo "UNKNOWN - $CONTAINER does not exist."
exit 3
if [ "$RUNNING" == "false" ]; then
echo "CRITICAL - $CONTAINER is not running."
exit 2
GHOST=$(docker inspect --format="{{ .State.Ghost }}" $CONTAINER)
if [ "$GHOST" == "true" ]; then
echo "WARNING - $CONTAINER has been ghosted."
exit 1
STARTED=$(docker inspect --format="{{ .State.StartedAt }}" $CONTAINER)
NETWORK=$(docker inspect --format="{{ .NetworkSettings.IPAddress }}" $CONTAINER)
echo "OK - $CONTAINER is running. IP: $NETWORK, StartedAt: $STARTED"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.