Created
August 10, 2023 13:42
-
-
Save ericsmalling/d33b2e6a809a697e2bcff820655509c2 to your computer and use it in GitHub Desktop.
Add arch to docker images output
This file contains hidden or 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 | |
# 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