Skip to content

Instantly share code, notes, and snippets.

@jeckel jeckel/docker_status.sh
Last active May 9, 2017

Embed
What would you like to do?
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
You can’t perform that action at this time.