Last active
April 25, 2025 10:02
-
-
Save eggplants/a046346571de66656f4d4d34de69fdd0 to your computer and use it in GitHub Desktop.
How to get information from ghcr Docker Registry HTTP API V2 with curl
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
#!/usr/bin/env bash | |
# ref: https://git.521000.bestmunity/t/how-to-check-if-a-container-image-exists-on-ghcr/154836/3 | |
# public image's {USER}/{IMAGE} | |
USER_IMAGE=eggplants/asciiquarium-docker | |
# get token ('{"token":"***"}' -> '***') | |
TOKEN="$( | |
curl "https://ghcr.io/token?scope=repository:${USER_IMAGE}:pull" | | |
awk -F'"' '$0=$4' | |
)" | |
_curl(){ curl -H "Authorization: Bearer ${TOKEN}" "$1" } | |
# get tags | |
_curl "https://ghcr.io/v2/${USER_IMAGE}/tags/list" | |
# get manifest of the latest image | |
_curl "https://ghcr.io/v2/${USER_IMAGE}/manifests/latest" |
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
{ | |
"mediaType": "application/vnd.docker.distribution.manifest.v2+json", | |
"schemaVersion": 2, | |
"config": { | |
"mediaType": "application/vnd.docker.container.image.v1+json", | |
"digest": "sha256:fb4552eacdc8e01082f87bae6a0fec6e1b61630f0a1e5a0e6a699d05ff0337fd", | |
"size": 5551 | |
}, | |
"layers": [ | |
{ | |
"mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip", | |
"digest": "sha256:4be315f6562fccf08fd6c749557e31e45ab6d987370e20e2c4933ddb04ddd5ff", | |
"size": 27140664 | |
}, | |
{ | |
"mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip", | |
"digest": "sha256:f6722131500bb303e9a66464a1d7a3805efaa2db3715d5204f5bdb89656a0589", | |
"size": 200 | |
}, | |
{ | |
"mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip", | |
"digest": "sha256:ac65630ca76f500df10c4676ec0fe8623070f1ab3394b8c2f4c6db4a48ebfa6c", | |
"size": 14894913 | |
}, | |
{ | |
"mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip", | |
"digest": "sha256:380348d1c396f3eb3c542ccc62b73383297b6a48b625f9671f59c109d964954e", | |
"size": 43915124 | |
}, | |
{ | |
"mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip", | |
"digest": "sha256:49470ea4d7663bcafd377eeeeda4d15445b09043f2dbf7d5f2865a66fbadcc44", | |
"size": 604613 | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Did you ever figure this out? I'm having the exact same issue. :)