Last active
January 6, 2023 21:16
-
-
Save yarcowang/370e63e68972afbff970 to your computer and use it in GitHub Desktop.
simple bash script to show log for a docker image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great script. Thank you for sharing, sir 👍