Skip to content

Instantly share code, notes, and snippets.

@ericsmalling
Created August 10, 2023 13:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ericsmalling/d33b2e6a809a697e2bcff820655509c2 to your computer and use it in GitHub Desktop.
Save ericsmalling/d33b2e6a809a697e2bcff820655509c2 to your computer and use it in GitHub Desktop.
Add arch to docker images output
#!/bin/bash
# Set the IFS variable to a newline character
IFS=$'\n'
# Get the list of docker images
images=$(docker images -a)
# Loop through the list of images
for image in $images; do
# Skip the header line
if [[ $image == *"REPOSITORY"* ]]; then
printf "%s \t%s\n" "$image" "ARCHITECTURE"
continue
fi
# Get the architecture of the image
id=$(echo $image | awk '{print $3}')
architecture=$(docker image inspect $id | jq -r '.[].Architecture')
# Append the architecture to the end of the line, color architecure red if not same as this machine
if [[ $architecture != $(uname -m) ]]; then
color="$(tput setaf 1)"
else
color=""
fi
printf "%s \t%s%s\e[0m\n" "$image" "$color" "$architecture"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment