Created
August 5, 2026 14:16
-
-
Save rtsui-harmonicinc/e074ef2786d778c25029dc225a2976d8 to your computer and use it in GitHub Desktop.
Inspect an image without downloading it (chatgpt enhanced)
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 | |
| # https://stackoverflow.com/questions/33352901/get-the-size-of-a-docker-image-before-a-pull | |
| dockersize() { docker manifest inspect -v "$1" | jq -c 'if type == "array" then .[] else . end | select(.Descriptor.platform.architecture != "unknown")' | jq -r '[ ( .Descriptor.platform | [ .os, .architecture, .variant, ."os.version" ] | del(..|nulls) | join("/") ), ( [ ( .OCIManifest // .SchemaV2Manifest ).layers[].size ] | add ) ] | join(" ")' | numfmt --to iec --format '%.2f' --field 2 | sort | column -t; } | |
| skopeosize() { | |
| local image="docker://$1" | |
| local repository="$image" | |
| local manifest | |
| if [[ "${image##*/}" == *:* ]]; then | |
| repository="${image%:*}" | |
| fi | |
| manifest=$(skopeo inspect --raw "$image") || return | |
| if jq -e '(.manifests // []) | length > 0' >/dev/null <<<"$manifest"; then | |
| jq -r '.manifests[] | select(.platform.architecture != null and .platform.architecture != "unknown") | [ .platform.os, .platform.architecture, .digest, .platform.variant ] | @tsv' <<<"$manifest" | | |
| while IFS=$'\t' read -r os architecture digest variant; do | |
| skopeo inspect "$repository@$digest" | | |
| jq -r --arg os "$os" --arg architecture "$architecture" --arg variant "$variant" '[ ( [ $os, $architecture, $variant ] | map(select(. != null and . != "")) | join("/") ), ( [ .LayersData[].Size ] | add ) ] | join(" ")' | |
| done | |
| else | |
| skopeo inspect --override-os linux "$image" | | |
| jq -r '[ ( [ .Os, .Architecture ] | map(select(. != null and . != "")) | join("/") ), ( [ .LayersData[].Size ] | add ) ] | join(" ")' | |
| fi | numfmt --to iec --format '%.2f' --field 2 | column -t | |
| } | |
| if command -v docker >/dev/null 2>&1; then | |
| dockersize "$@" | |
| elif command -v skopeo >/dev/null 2>&1; then | |
| skopeosize "$@" | |
| else | |
| echo "Neither docker nor skopeo is installed." >&2 | |
| return 1 | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment