Skip to content

Instantly share code, notes, and snippets.

@mrchoke
Last active April 15, 2022 06:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mrchoke/962d05f4681790078f60e8b8f1710060 to your computer and use it in GitHub Desktop.
Save mrchoke/962d05f4681790078f60e8b8f1710060 to your computer and use it in GitHub Desktop.
# การแสดงประวัติการสร้าง Docker image ด้วยคำสั่ง docker history
#!/bin/bash
# MrChoke
# Ref: https://docs.docker.com/engine/reference/commandline/history/
# Ref: https://stackoverflow.com/questions/19104847/how-to-generate-a-dockerfile-from-an-image
if [ $# -eq 0 ]; then
echo "No docker image provided."
echo -e "Example:\n"
echo -e "$0 nginx:latest\n"
exit 1
fi
docker history \
--no-trunc \
--format "{{.CreatedBy}}" \
$1 \
| tac \
| awk '
{
gsub(/^\/bin\/sh \-c #\(nop\) /,"");
gsub(/^\/bin\/sh \-c /,"RUN ");
gsub(/\/bin\/sh \-c /,"");
gsub(/^[ \t]+|[ \t]+$/,"");
gsub(/ && /,"\\\n & ")
}1'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment