Skip to content

Instantly share code, notes, and snippets.

@cupracer
Created August 23, 2022 08:49
Show Gist options
  • Save cupracer/2a77cd071f8cc74cf39a04c683ad54da to your computer and use it in GitHub Desktop.
Save cupracer/2a77cd071f8cc74cf39a04c683ad54da to your computer and use it in GitHub Desktop.
Get all steps used during container image building (aka Dockerfile instructions)
#!/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