Skip to content

Instantly share code, notes, and snippets.

@kccheung
Forked from yarcowang/docker-log.sh
Created August 11, 2016 04:08
Show Gist options
  • Save kccheung/df88062c9f396b53f07cb27ff025d402 to your computer and use it in GitHub Desktop.
Save kccheung/df88062c9f396b53f07cb27ff025d402 to your computer and use it in GitHub Desktop.
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 [ $l -gt 0 ]; then
l=$((l - 1))
fi
content="$commit
$($DOCKER inspect $commit | tr -d '\"' | grep 'Created\|Author\|Comment')"
echo "$content"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment