Last active
March 15, 2018 21:40
-
-
Save lalyos/9c4ce959a3e8366b716d2b4ab9329383 to your computer and use it in GitHub Desktop.
docker registry donload alpine layer blob
This file contains 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
token() { | |
scope=${1:?scope required} | |
export T=$(curl -s 'https://auth.docker.io/token?service=registry.docker.io&scope=repository:'$scope | jq .token -r; ) | |
} | |
blobUrl() { | |
repo=${1:?required repo (library/alpine)} | |
token ${repo}:pull | |
export BLOBURL=$(curl -Lsi -H "Authorization: Bearer $T" https://registry-1.docker.io/v2/library/alpine/blobs/${BLOB}| sed -n '/^Location:/ {s/.$//;s/Location: //p;}') | |
echo BLOBURL=$BLOBURL | |
} | |
pullImage() { | |
image=${1:? required image (library/alpine)} | |
set -x | |
token ${image}:pull | |
BLOB=$(curl -s -H "Authorization: Bearer $T" https://registry-1.docker.io/v2/${image}/manifests/latest| jq '.fsLayers[-1].blobSum' -r) | |
mkdir -p ${image#*/} | |
curl -Ls -H "Authorization: Bearer $T" https://registry-1.docker.io/v2/${image}/blobs/${BLOB} | tar -xzv -C ${image#*/} | |
set +x | |
} | |
pullImage library/alpine | |
pullImage library/busybox |
This file contains 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
# download 1 single docker image layer (https://github.com/docker-library/golang/blob/9bf6daddb324a4d8e82b0613cf348a6eff363f95/1.10/alpine3.7/Dockerfile#L10) | |
# and untar the relevant dir (usr/local/go) into '/' | |
# first you have to ask for a fresh Bearer token with scope=repository:library/img:tag | |
# apk add --no-cache curl jq bash && bash | |
curl -Ls \ | |
-H "Authorization: Bearer $(curl -s 'https://auth.docker.io/token?service=registry.docker.io&scope=repository:library/golang:pull' | jq .token -r)" \ | |
https://registry-1.docker.io/v2/library/golang/blobs/sha256:6487ee6212c57a47feb500f1421c38a83cd1ab7def383ffc49804d9d56970cbb \ | |
| tar -xzv -T <(echo usr/local/go) -C / | |
export PATH=/usr/local/go/bin/:$PATH | |
go version |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment