Skip to content

Instantly share code, notes, and snippets.

@jeckel
Last active May 9, 2017 14:48
Show Gist options
  • Save jeckel/6610fb2211044a4380d80da0ac1993db to your computer and use it in GitHub Desktop.
Save jeckel/6610fb2211044a4380d80da0ac1993db to your computer and use it in GitHub Desktop.
docker_status.sh
#!/bin/bash
function docker_status() {
local CONTAINER=$1
local RUNNING=$(docker inspect --format="{{.State.Running}}" $CONTAINER 2> /dev/null)
if [ $? -eq 1 ]; then
echo "$CONTAINER does not exist."
else
if [ "$RUNNING" == "false" ]; then
echo "$CONTAINER is not running."
else
local STARTED=$(docker inspect --format="{{.State.StartedAt}}" $CONTAINER)
local NETWORK=$(docker inspect --format="{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}" $CONTAINER)
echo "$CONTAINER is running. IP: $NETWORK, StartedAt: $STARTED"
fi
fi
}
docker_status $1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment