Skip to content

Instantly share code, notes, and snippets.

@leoh0
Last active August 16, 2018 23:12
Show Gist options
  • Select an option

  • Save leoh0/1bd75f4f84448f416d2447dc62d8fd7d to your computer and use it in GitHub Desktop.

Select an option

Save leoh0/1bd75f4f84448f416d2447dc62d8fd7d to your computer and use it in GitHub Desktop.
Use docker hub as a public accessible storage when you need to upload and download large file for free.

docker_as_a_storage

Upload with docker, download with only curl.

  1. upload your file
REPO=YOUR_DOCKER_ID ./docker_as_a_storage.sh <file or directory>
  1. after finished then get command for downloading your file

  2. then paste when you need to download this file

curl -fSL --progress   -H "Authorization: Bearer $(curl -fsSL "https://auth.docker.io/token?service=registry.docker.io&scope=repository:leoh0/tty.gif:pull" | sed 's/.*"token":"\([^"]*\)".*/\1/g')"   https://registry-1.docker.io/v2/leoh0/tty.gif/blobs/sha256:55f44f7164fde0e4422d65494141fee97142a5c2ece7e63cfa34944a1437e3a8 | tar xzvf -

#!/usr/bin/env bash
REPO=${REPO:-leoh0}
clean_up() {
rm -rf ${temp}
}
trap clean_up EXIT
temp=$(mktemp -d)
target=$(echo "$1" | sed 's/\/$//g')
add_target=$(echo "$target" | awk -F "/" '{print $NF}')
cp -r "$target" "$temp"
pushd $temp > /dev/null
cat >DockerFile << EOF
FROM scratch
COPY ${add_target} /${add_target}
EOF
time=$(date +"%y%m%d%H%M%S")
echo
echo -e "\033[0;33mBuild image\033[0m \033[0;32m ✔\033[0m"
docker build -t ${REPO}/${add_target}:${time} -f DockerFile .
echo
echo -e "\033[0;33mPush image\033[0m \033[0;32m ✔\033[0m"
docker push ${REPO}/${add_target}:${time}
image="${REPO}/${add_target}"
imageTag="${time}"
digest="${imageTag}"
token="$(curl -fsSL "https://auth.docker.io/token?service=registry.docker.io&scope=repository:$image:pull" | sed 's/.*"token":"\([^"]*\)".*/\1/g')"
rawjson=$(curl -fsSL \
-H "Authorization: Bearer $token" \
-H 'Accept: application/vnd.docker.distribution.manifest.v2+json' \
"https://registry-1.docker.io/v2/$image/manifests/$digest")
digest=$(echo $rawjson | sed 's/.*layers":.*"digest": "\([^\"].*\)\".*/\1/g')
popd > /dev/null
echo
echo -e "\033[0;35mUse below command\033[0m \033[0;32m ✔\033[0m"
echo
echo "curl -fSL --progress \
-H \"Authorization: Bearer \$(curl -fsSL \"https://auth.docker.io/token?service=registry.docker.io&scope=repository:${REPO}/${add_target}:pull\" | sed 's/.*\"token\":\"\([^\"]*\)\".*/\1/g')\" \
https://registry-1.docker.io/v2/${REPO}/${add_target}/blobs/${digest} | tar xzvf -"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment