What’s in a Docker image?

#!/bin/sh# the image that we want to download
export IMAGE="timburks/tiny"
# first we need to get an auth token with the access
# permissions that we need
export AUTHURL="https://auth.docker.io/token?scope=repository:$IMAGE:pull&service=registry.docker.io"
export TOKEN=`curl --silent $AUTHURL | jq -r '.token'`
# next we fetch the manifest and extract the layer digests
export DIGESTS=`curl \
--silent \
--header "Accept: application/vnd.docker.distribution.manifest.v2+json" \
--header "Authorization: Bearer $TOKEN" \
"https://registry-1.docker.io/v2/$IMAGE/manifests/latest" \
| jq -r '.layers[].digest'`
# each digest is the name of a blob containing an image layer
echo $DIGESTS
# we'll put the layers of the image in a directory named 'layers'
# watch out for name collisions!
rm -rf layers
mkdir layers
LAYER=0
for DIGEST in $DIGESTS ; do
echo $DIGEST
curl --silent --location \
--header "Authorization: Bearer $TOKEN" \
https://registry-1.docker.io/v2/$IMAGE/blobs/$DIGEST \
-o layers/layer-$LAYER.tgz
LAYER=$((LAYER+1))
done
# now you can look inside or unpack each image with tar.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Tim Burks

Tim Burks

Software developer in the SF Bay area. Electronic Design Automation, iOS apps, and now API tools for the world’s largest computer.