Skip to content

Instantly share code, notes, and snippets.

@tlrobinson
Last active October 18, 2023 21:59
Show Gist options
  • Save tlrobinson/c85dca269f4405ad4201 to your computer and use it in GitHub Desktop.
Save tlrobinson/c85dca269f4405ad4201 to your computer and use it in GitHub Desktop.
Quick and dirty "docker pull"-like shell script.
#!/usr/bin/env bash
set -eu
name="library/redis"
tag="latest"
registry="https://registry-1.docker.io"
blobs="blobs"
data="images/$name/$tag"
image="$data/image"
manifest="$data/manifest.json"
rm -rf "$image"
mkdir -p "$blobs" "$data" "$image"
# get the manifest.json
curl -L "$registry/v2/manifest/$name/$tag" -o "$manifest"
# for each layer in the manifest
jq -r '.fsLayers[] | .blobSum' < "$manifest" | tail -r | sed 's/:/\//' | while read blobsum; do
blobsumpath="$blobs/$(basename "$blobsum")"
# download the layer. -z checks to see if the file has been downloaded
curl -L "$registry/v2/blob/$name/$blobsum" -z "$blobsumpath" -o "$blobsumpath"
# extract the layer
tar -x -f "$blobsumpath" -C "$image"
# delete .wh.* and their corresponding files
find "$image" -name '.wh.*' -print -exec sh -c 'rm -rf "{}" "$(echo "{}" | sed s/.wh.//)"' \; 2> /dev/null || true
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment