Hike News
Hike News

下载谷歌镜像的几种姿势

前言

在国内,因为墙的存在所以很多国外网站不能访问,这其中就有谷歌镜像网站gcr.io,不过我们可以通过其他方式使用谷歌的镜像。

通过国内镜像站

阿里云镜像站

域名:registry.cn-hangzhou.aliyuncs.com/google_containers

微软镜像站

域名:gcr.azk8s.cn/google_containers

中科大镜像站(拉取速度较慢)

域名:gcr.mirrors.ustc.edu.cn/google_containers

使用方式

替换谷歌镜像地址为国内镜像站地址,比如:

k8s.gcr.io开头的k8s.gcr.io/coredns:1.1.3

1
2
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:1.1.3
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:1.1.3 k8s.gcr.io/coredns:1.1.3

gcr.io开头的gcr.io/google_containers/heapster-amd64:v1.5.3

1
2
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/heapster-amd64:v1.5.3
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/heapster-amd64:v1.5.3 gcr.io/google_containers/heapster-amd64:v1.5.3

通过配置代理

前提是有一台能够科学上网的机器,并且目标机器能访问到可以科学上网的机器。

  1. 为docker服务创建systemd插件目录:
1
mkdir -p /etc/systemd/system/docker.service.d
  1. 配置代理文件
1
2
3
4
cat >/etc/systemd/system/docker.service.d/http-proxy.conf<EOF 
[Service]
Environment="HTTP_PROXY=http://proxy.example.com:80/"
EOF
  1. 刷新配置并重启Docker
1
2
systemctl daemon-reload
systemctl restart docker
  1. 验证配置是否加载
1
2
systemctl show --property=Environment docker
Environment=HTTP_PROXY=http://proxy.example.com:80/

如果配置已经加载但还是不能下载谷歌镜像,可以试试把HTTP_PROXY改成http_proxy,我的配置是Environment="http_proxy=http://10.208.204.147:1080/"才能使用。

HTTPS_PROXYNO_PROXY配置类似,具体可以看官网代理配置

通过脚本

1
curl -sSL https://git.io/getgcr | bash -s  k8s.gcr.io/kube-apiserver:v1.14.3

k8s.gcr.io/kube-apiserver:v1.14.3替换成要下载的目标镜像即可。

该方法本质上还是通过国内镜像站下载的。

参考

http://mirror.azure.cn/help/gcr-proxy-cache.html

https://blog.docker.com/2015/10/registry-proxy-cache-docker-open-source/

https://stackoverflow.com/questions/23111631/cannot-download-docker-images-behind-a-proxy