Skip to content

Instantly share code, notes, and snippets.

@longkai
Last active January 20, 2020 11:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save longkai/123c55a5ac2fdd3236e0eed44de39bb2 to your computer and use it in GitHub Desktop.
Save longkai/123c55a5ac2fdd3236e0eed44de39bb2 to your computer and use it in GitHub Desktop.
pull a docker image from a mirror source
#!/bin/bash
repo=azk8s.cn
function rip() {
echo $1 | awk -F '/' '{
{
if (NF == 1)
print "dockerhub." repo "/library/" $0
else if ($1 == "docker.io")
print "dockerhub." repo "/" substr($0, length($1)+2, length($0)-length($1))
else if ($1 == "k8s.gcr.io")
print "gcr." repo "/google_containers/" substr($0, length($1)+2, length($0)-length($1))
else if ($1 == "gcr.io")
print "gcr." repo "/" substr($0, length($1)+2, length($0)-length($1))
else if ($1 == "quay.io")
print "quay." repo "/" substr($0, length($1)+2, length($0)-length($1))
else
print "dockerhub." repo "/" $0
}
}' repo=$repo
}
function pull() {
url=`rip $1`
docker pull $url
docker tag $url $1
docker rmi $url
}
function file() {
while IFS= read -r line; do
echo "docker pull: $line"
pull $line
done < $1
}
if [ $1 == "-f" ]; then
file $2
else
pull $1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment