Skip to content

Instantly share code, notes, and snippets.

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 ahachete/8e9255bbd3834d7f3b0ad7c0cbb6069f to your computer and use it in GitHub Desktop.
Save ahachete/8e9255bbd3834d7f3b0ad7c0cbb6069f to your computer and use it in GitHub Desktop.
A simple script to demonstrate how to fetch and unpack a container image from a registry. Used here with the latest version of the Postgres image
#!/bin/sh
TOKEN=$( curl -s "https://auth.docker.io/token?service=registry.docker.io&scope=repository:library/postgres:pull" \
| jq -r .token )
MANIFEST_INDEX=$( curl -s -H "Authorization: Bearer $TOKEN" \
https://registry-1.docker.io/v2/library/postgres/manifests/latest )
AMD64_MANIFEST_DIGEST=$( echo $MANIFEST_INDEX \
|jq -r '.manifests[] | select(.platform.architecture == "amd64") .digest' )
AMD64_MANIFEST=$( curl -s -H "Authorization: Bearer $TOKEN" \
-H "Accept: application/vnd.oci.image.manifest.v1+json" \
https://registry-1.docker.io/v2/library/postgres/manifests/$AMD64_MANIFEST_DIGEST )
LAYERS=$( echo $AMD64_MANIFEST \
|jq -r '.layers[] | select(.mediaType == "application/vnd.oci.image.layer.v1.tar+gzip") .digest' )
tempfile=/tmp/$(date +%N)
mkdir $tempfile
cd $tempfile
for layer in $LAYERS
do
curl -s -H "Authorization: Bearer $TOKEN" --location \
https://registry-1.docker.io/v2/library/postgres/blobs/$layer \
| tar xzf -
done
echo "Image unpackaged at $tempfile"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment