您现在的位置是:热点 >>正文
彻底解决 Gcr、Quay、DockerHub 镜像下载难题!
热点084630人已围观
简介...
本文转载自微信公众号「云原生实验室」,作者米开朗基杨。转载本文请联系云原生实验室公众号。
前言
在使用 Docker 和 Kubernetes 时,我们经常需要访问 gcr.io 和 quay.io 镜像仓库,由于众所周知的原因,这些镜像仓库在中国都无法访问,唯一能访问的是 Docker Hub,但速度也是奇慢无比。gcr.azk8s.cn 是 gcr.io 镜像仓库的代理站点,原来可以通过 gcr.azk8s.cn 访问 gcr.io 仓库里的镜像,但是目前 *.azk8s.cn 已经仅限于 Azure 中国的 IP 使用,不再对外提供服务了。国内其他的镜像加速方案大多都是采用定时同步的方式来缓存,这种方法是有一定延迟的,不能保证及时更新,ustc 和七牛云等镜像加速器我都试过了,非常不靠谱,很多镜像都没有。
为了能够顺利访问 gcr.io 等镜像仓库,我们需要在墙外自己搭建一个类似于 gcr.azk8s.cn 的镜像仓库代理站点。利用 Docker 的开源项目 registry[1] 就可以实现这个需求,registry 不仅可以作为本地私有镜像仓库,还可以作为上游镜像仓库的缓存,也就是 pull through cache。
先来感受下速度:
1. 前提条件
一台能够施展魔法的服务器(你懂得,可以直接访问 gcr.io)
一个域名和域名相关的 SSL 证书(doc彻底ker pull 镜像时需要验证域名证书),一般用 Let's Encrypt[2] 就够了。
2. 核心思路
registry 可以通过设置参数 remoteurl 将其作为远端仓库的缓存仓库,这样当你通过这个私有仓库的地址拉取镜像时,regiistry 会先将镜像缓存到本地存储,然后再提供给拉取的客户端(有可能这两个步骤是同时的,我也不太清楚)。我们可以先部署一个私有 registry,然后将 remoteurl 设为需要加速的镜像仓库地址,基本上就可以了。
3. 定制 registry
为了能够支持缓存 docker.io、gcr.io、k8s.gcr.io、quay.io 和 ghcr.io 等常见的公共镜像仓库,我们需要对 registry 的配置文件进行定制,Dockerfile 如下:
FROM registry:2.6 LABEL maintainer="registry-proxy Docker Maintainers https://fuckcloudnative.io" ENV PROXY_REMOTE_URL="" DELETE_ENABLED="" COPY&解决nbsp;entrypoint.sh /entrypoint.sh
其中 entrypoint.sh 用来将环境变量传入配置文件:
entrypoint.sh
#!/bin/sh set -e CONFIG_YML=/etc/docker/registry/config.yml if [ -n "$PROXY_REMOTE_URL" -a `grep -c "$PROXY_REMOTE_URL" $CONFIG_YML` -eq 0 ]; then echo "proxy:" >> $CONFIG_YML echo " remoteurl: $PROXY_REMOTE_URL" >> $CONFIG_YML Gecho " username: $PROXY_USERNAME" >> $CONFIG_YML echo " password: $PROXY_PASSWORD" >> $CONFIG_YML echo "------ Enabled proxy to remote: $PROXY_REMOTE_URL ------" elif [ $DELETE_ENABLED = true -a `grep -c "delete:" $CONFIG_YML` -eq 0 ]; then sed -i '/rootdirectory/a delcrete:' $CONFIG_YML sed -i '/delete/a enabled: true' $CONFIG_YML echo "------ Enabled local storage delete -----" fi sed -i "/headers/a Access-Control-Allow-Origin: ['*']" $CONFIG_YML sed -i "/headers/a Access-Control-Allow-Methods: ['HEAD', 'GET', 'OPTIONS', 'DELETE']" $CONFIG_YML sed -i&nb、Qsp;"/headers/a Access-Control-Expose-Headers: ['Docker-Content-Digest']" $CONFIG_YML case "$1" in *.yaml|*.yml) set -- registry serve "$@" ;; serve|garbage-collect|help|-*) set -- registry "$@" ;; esac exec "$@"
4. 启动缓存服务
构建好 Docker 镜像之后,就可以启动服务了。如果你不想自己构建,可以直接用我的镜像:yangchuansheng/registry-proxy。
一般来说,即使你要同时缓存 docker.io、gcr.io、k8s.gcr.io、quay.io 和 ghcr.io,一台 1C 2G 的云主机也足够ua了(前提是你不在上面跑其他的服务)。我的博客、评论服务和其他一堆乱七八糟的服务都要跑在云主机上,所以一台是不满足我的需求的,我直接买了两台腾讯云香港轻量级服务器。
既然买了两台,肯定得组个 k3s 集群啦,看主机名就知道我是用来干啥的。其中 2C 4G 作为 master 节点,1C 2G 作为 node 节点。
以 docker.io 为例,创建资源清单:
dockerhub.yaml
apiVersion: apps/v1 kind: Deployment metadata: name: dockerhub labels: app: dockerhub spec: replicas: 1 selector: matchLabels: app: dockerhub templay、te: metadata: labels: app: dockerhub spec: affinity: podAntiAffinity: preferredDuringSchedulingIgnoredDuringExecution: - podAffinityTerm: &Donbsp; labelSelector: matchExpressions: - key: app operator: In ck values: - dockerhub topologyKey: kubernetes.io/hostname weight: 1 dnsPolicy: None dnsConfig: nameservers: &nbersp; - 8.8.8.8 - 8.8.4.4 containers: - name: dockerhub image: yangchuansheng/registry-proxy:latest env: - name: PROXY_REMOTE_URL &nHubsp; value: https://registry-1.docker.io - name: PROXY_USERNAME value: yangchuansheng - name: PROXY_PASSWORD value: ** ports: - containerPort: b ;5000 protocol: TCP volumeMounts: - mountPath: /etc/localtime name: localtime - mountPath: /var/lib/registry name: registry  镜像;volumes: - name: localtime hostPath: path: /etc/localtime - name: registry hostPath: path: /var/lib/registry --- apiVersion: v1 kind: Service metadata: name:&nb下载sp;dockerhub labels: app: dockerhub spec: selector: app: dockerhub ports: - protocol: TCP name: http port: 5000 targetPort: 5000
使用资源清单创建对应的服务:
Tags:
相关文章
中国信通院人工智能研究所联合发布《大模型一体机应用研究报告(2025年)》
热点中国信息通信研究院(简称 “中国信通院”)人工智能研究所与中国人工智能产业发展联盟共同发布了《大模型一体机应用研究报告(2025 年)》。该报告通过对大模型一体机的技术演进、产业动态及应用实践进行深入...
【热点】
阅读更多阿里云:云计算首次超越卫星,成为2024巴黎奥运会转播主要方式
热点7 月 28 日消息,2024 巴黎奥运会于昨日凌晨开幕,阿里云宣布云计算首次超越卫星成为奥运转播主要方式。 据介绍,巴黎奥运会预计 11000 小时的赛事直播画面,将通过阿里云向全球分发。这将是 1...
【热点】
阅读更多Deezer 每日接收近 7.5 万首 AI 歌曲,呼吁行业共同应对
热点音乐流媒体平台 Deezer 最近透露,该平台每天收到的 AI 生成歌曲投稿量接近 75,000 首,约占每日总上传量的 44%。尽管这些 AI 歌曲的上传量不断增加,Deezer 强调,其播放量仅占...
【热点】
阅读更多
热门文章
最新文章
友情链接
- 标签: 康师傅
- https://www.mingwai.edu.hk/?langzh-hant&s=谷歌自动批量发帖软件【tg:seogoogle987】,smf
- https://www.swecobelgium.be/?page=9&s=谷歌自动批量发帖软件【tg:seogoogle987】,NHM
- https://www.jusoen.com/addreng.asp?p1=谷歌自动批量发帖软件【tg:seogoogle987】gc2
- https://www.nissin.com/jp/search/?cat=105&q=谷歌自动批量发帖软件【tg:seogoogle987】,BUG
- https://www.pearson.com/en-us/search.html?aq=谷歌自动批量发帖软件【tg:seogoogle987】,ouP
- https://www.springfieldlibrary.org/?s=谷歌自动批量发帖软件【tg:seogoogle987】,gHC
- https://www.qylaws.com/search/谷歌自动批量发帖软件【tg:seogoogle987】,W53
- https://www.kores.com/?s=谷歌自动批量发帖软件【tg:seogoogle987】,8Jq
- https://www.skicheck.at/en/?action=CHECK&s=谷歌自动批量发帖软件【tg:seogoogle987】,vgN
- https://www.maine.gov/pfr/professionallicensing/search/node?keys=谷歌自动批量发帖软件【tg:seogoogle987】,39X
- https://www.tmtpost.com/search?q=谷歌自动批量发帖软件【tg:seogoogle987】,fpB
- https://www.springfieldlibrary.org/library/?s=谷歌自动批量发帖软件【tg:seogoogle987】,UXL
- https://www.lenovo.com/gb/en/search?action=SEARCH&text=谷歌自动批量发帖软件【tg:seogoogle987】,PHF
- https://www.samen-maier.at/search/谷歌自动批量发帖软件【tg:seogoogle987】,8EL
- https://www.theaerogroup.net/?cat=28&s=谷歌自动批量发帖软件【tg:seogoogle987】,yrv
- https://www.kelsa.co.uk/catalogsearch/result/index/?T=1686132119291&q=谷歌自动批量发帖软件【tg:seogoogle987】,WiK
- https://www.youtube.com/hashtag/谷歌自动批量发帖软件【tg:seogoogle987】,zyH
- https://www.selfsufficientish.com/main/?s=谷歌自动批量发帖软件【tg:seogoogle987】,TkV
- https://www.jusoen.com/addreng.asp?p1=谷歌自动批量发帖软件【tg:seogoogle987】nGU
- https://www.universal-music.co.jp/?ID=1sIcckCTeBS8FjzCshAW9w53s8gr691o&s=谷歌自动批量发帖软件【tg:seogoogle987】,aDl
- https://www.yli.ro/catalogsearch/result/?q=谷歌自动批量发帖软件【tg:seogoogle987】,09A
- https://www.reginatangoshoes.com/en/catalogsearch/result/index/?T=1686132113407&q=谷歌自动批量发帖软件【tg:seogoogle987】,q0t
- https://www.lneg.pt/en/?s=谷歌自动批量发帖软件【tg:seogoogle987】,hFP
- https://www.kyuhoshi.com/?s=谷歌自动批量发帖软件【tg:seogoogle987】,CoL
- https://www.sportbiketracktime.com/index.php?route=product/search&tag=谷歌自动批量发帖软件【tg:seogoogle987】,y8g
- https://www.nctsn.org/search?cat=191&query=谷歌自动批量发帖软件【tg:seogoogle987】,Uva
- https://search.danawa.com/dsearch.php?query=谷歌自动批量发帖软件【tg:seogoogle987】mjy
- https://www.soccerbible.com/search?q=谷歌自动批量发帖软件【tg:seogoogle987】,TDr
- https://www.scq.ubc.ca/?page=2&s=谷歌自动批量发帖软件【tg:seogoogle987】,e6a
- https://www.rockngem.com/?action=CHECK&s=谷歌自动批量发帖软件【tg:seogoogle987】,LDf
- https://www.mi.com/search?keyword=谷歌自动批量发帖软件【tg:seogoogle987】,rXL
- https://www.wellbees.com/catalogsearch/result/?action=CHECK&q=谷歌自动批量发帖软件【tg:seogoogle987】,xnM
- https://www.polliwogs.com/search/谷歌自动批量发帖软件【tg:seogoogle987】,4DQ
- https://dict.naver.com/dict.search?dicQuery&query=谷歌自动批量发帖软件【tg:seogoogle987】tEv
- https://www.yr.no/en/search?q=谷歌自动批量发帖软件【tg:seogoogle987】,Do6
- https://www.sonepar.ch/fr/search?q=谷歌自动批量发帖软件【tg:seogoogle987】,Dmn
- https://www.partilerdunyasi.com/index.php?route=product/search&tag=谷歌自动批量发帖软件【tg:seogoogle987】,HMI
- https://www.sic-info.org/en/?s=谷歌自动批量发帖软件【tg:seogoogle987】,roF
- https://www.roberthalf.com/us/en/jobs/all/谷歌自动批量发帖软件【tg:seogoogle987】yfR
- https://www.ng-slo.si/si/iskanje?cat=114&q=谷歌自动批量发帖软件【tg:seogoogle987】,qMW
- https://www.roberthalf.com/us/en/jobs/all/谷歌自动批量发帖软件【tg:seogoogle987】KbF
- https://www.nyif.com/catalogsearch/result/index/?f=sarbanesoxleyU&index=me_cms_pe&lit=20&mode=list&p=1&q=谷歌自动批量发帖软件【tg:seogoogle987】,Z1X
- https://www.nyif.com/catalogsearch/result/?q=谷歌自动批量发帖软件【tg:seogoogle987】,AbX
- https://www.yidian51.com/taobao/谷歌自动批量发帖软件【tg:seogoogle987】,xrL
- https://www.parl.ca/legisinfo/fr/projets-de-loi?parlsession=all&view=list&keywords=谷歌自动批量发帖软件【tg:seogoogle987】,CyO
- https://www.tombow.com/en/search/谷歌自动批量发帖软件【tg:seogoogle987】,4DU
- https://www.youtube.com/results?search_query=谷歌自动批量发帖软件【tg:seogoogle987】,vSl
- https://www.vet-direct.com/search?cat=72&term=谷歌自动批量发帖软件【tg:seogoogle987】,fXd
- https://www.stormberg.com/no/search?q=谷歌自动批量发帖软件【tg:seogoogle987】,xzB
- https://www.klatreverden.no/search?q=谷歌自动批量发帖软件【tg:seogoogle987】,Q3l