Skip to content

Instantly share code, notes, and snippets.

@longkai

longkai/docker-pull.sh

Last active Jan 20, 2020
Embed
What would you like to do?
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