Skip to content

Instantly share code, notes, and snippets.

@princebot
Created October 31, 2015 22:39
Show Gist options
  • Save princebot/2822b14f838621d99f3d to your computer and use it in GitHub Desktop.
Save princebot/2822b14f838621d99f3d to your computer and use it in GitHub Desktop.
# Bash shell function that runs "docker inspect" and pipes the output through jq.
# Requires jq [https://stedolan.github.io/jq/]
#
# Usage: di CONTAINER|IMAGE
di() (
error=1
__obj=$1
if [[ ! ${__obj} ]]; then
echo "${FUNCNAME}(): error: missing docker object argument" >&2
return ${error}
elif ! which jq &>/dev/null; then
echo "${FUNCNAME}(): error: missing required program \"jq\"" >&2
return ${error}
fi
__tmp=$(mktemp inspect.tmp.XXXXXXXX)
if (($?)); then
echo "${FUNCNAME}(): error: could not create tmp file" >&2
return ${error}
elif ! [[ ${__tmp} && -r ${__tmp} && -w ${__tmp} ]]; then
echo "${FUNCNAME}(): error: tmp file ${__tmp} is not read-write" >&2
return ${error}
fi
trap "[[ -f ${__tmp} ]] && rm -f ${__tmp}" EXIT RETURN
docker inspect "${__obj}" \
| jq -C '.' \
| tee "${__tmp}" \
| less -R
cat ${__tmp} 2>/dev/null
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment