Created
August 23, 2022 08:49
-
-
Save cupracer/2a77cd071f8cc74cf39a04c683ad54da to your computer and use it in GitHub Desktop.
Get all steps used during container image building (aka Dockerfile instructions)
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
#!/bin/bash | |
IMAGE=$1 | |
PARENT=$IMAGE | |
declare -a RESULTS REV_RESULTS | |
while [ -n "${PARENT}" ]; do | |
JSON=$(docker inspect $PARENT |jq .) | |
RESULTS+=("$(echo $JSON | jq '.[0]'.ContainerConfig.Cmd)") | |
PARENT=$(echo $JSON | jq '.[0]'.Parent |tr -d '\"') | |
echo $PARENT | grep -q ':' > /dev/null 2>&1 | |
if [ $? -eq 0 ]; then | |
PARENT=$(echo $PARENT | cut -d':' -f2) | |
fi | |
done | |
for (( i=${#RESULTS[@]}-1; i>=0; i-- )); do | |
REV_RESULTS[${#REV_RESULTS[@]}]=${RESULTS[i]} | |
done | |
for cmd in "${REV_RESULTS[@]}"; do | |
echo $cmd | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment