Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
simple bash script to show log for a docker image
#!/usr/bin/env bash
DOCKER=`which docker`
usage()
{
echo "Usage: $(basename $0) [-l num] IMAGE"
exit 0
}
if [ "$#" -lt 1 ]; then
usage
exit 0
fi
l="-1"
while getopts ":l:" opt;
do
case "$opt" in
l)
l=$OPTARG
;;
esac
done
shift $((OPTIND-1))
for commit in $($DOCKER history $1 | sed 1d | awk '{ print $1 }')
do
if [ $l -eq 0 ]; then
exit 0
elif [ "$commit" == "<missing>" ]; then
echo "...<missing commit ids>..."
exit 0
elif [ $l -gt 0 ]; then
l=$((l - 1))
fi
content="$commit
$($DOCKER inspect $commit | tr -d '\"' | grep 'Created\|Author\|Comment')"
echo "$content"
done
@nicksarafa

This comment has been minimized.

Copy link

commented May 27, 2017

Great script. Thank you for sharing, sir 👍

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.