Last active
January 20, 2020 11:22
-
-
Save longkai/123c55a5ac2fdd3236e0eed44de39bb2 to your computer and use it in GitHub Desktop.
pull a docker image from a mirror source
This file contains hidden or 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
#!/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