一文搞定 Docker 镜像加速:南大镜像源 + 国内主流方案
南京大学容器镜像加速服务参考来源南京大学 e-Science 中心 - 容器缓存服务官方开源镜像站https://mirror.nju.edu.cn 私服仓库https://repo.nju.edu.cn南京大学 e-Science 中心提供面向全球主流容器镜像仓库的缓存代理服务访问速度快、稳定可靠是国内拉取 GCR、GHCR、Quay、NGC 等海外镜像的最佳选择之一。一、镜像服务总表南大共提供5 个主流容器仓库的代理服务所有镜像地址只需把原始域名替换为对应的*.nju.edu.cn即可。镜像加速服务总表序号原始仓库全称原始地址替换前南大镜像地址替换后用途说明1Docker HubDocker Hub Registrydocker.iodocker.nju.edu.cn最基础的 Docker 官方镜像仓库2GCRGoogle Container Registrygcr.io、k8s.gcr.iogcr.nju.edu.cnGoogle 容器镜像服务含 K8s 相关镜像3GHCRGitHub Container Registryghcr.ioghcr.nju.edu.cnGitHub 提供的容器镜像服务4NGCNVIDIA GPU Cloudnvcr.iongc.nju.edu.cnNVIDIA GPU/AI 镜像服务5QuayQuay Container Registryquay.ioquay.nju.edu.cnRed Hat 旗下容器镜像服务二、Docker Hub 加速配置Linux将南大镜像作为 Docker daemon 的 registry-mirror之后docker pull nginx等命令会自动走加速通道。#!/bin/bash# 写入 daemon.jsonsudomkdir-p/etc/dockersudotee/etc/docker/daemon.json-EOF { registry-mirrors: [https://docker.nju.edu.cn] } EOF# 重载并重启 Dockersudosystemctl daemon-reloadsudosystemctl restartdocker# 验证配置是否生效dockerinfo|grep-A2Registry Mirrors三、其他仓库使用方法域名替换GCR / GHCR / NGC / Quay 这 4 个仓库不能通过 registry-mirrors 配置需要在docker pull命令中直接替换域名。原始拉取命令替换为南大镜像docker pull gcr.io/cadvisor/cadvisor:v0.39.3docker pull gcr.nju.edu.cn/cadvisor/cadvisor:v0.39.3docker pull ghcr.io/github/super-linter:latestdocker pull ghcr.nju.edu.cn/github/super-linter:latestdocker pull nvcr.io/nvidia/cuda:12.0.0-base-ubuntu22.04docker pull ngc.nju.edu.cn/nvidia/cuda:12.0.0-base-ubuntu22.04docker pull quay.io/prometheus/prometheus:latestdocker pull quay.nju.edu.cn/prometheus/prometheus:latest提示k8s.gcr.io上的镜像本质托管在 GCR 上可尝试用gcr.nju.edu.cn拉取对应路径。四、国内其他 Docker 镜像源汇总除了南京大学外国内还有多家高校和云厂商提供 Docker 镜像加速服务可作为备用或并行使用。4.1 高校 / 公益镜像源提供方Docker Hub 加速地址其他仓库支持备注南京大学https://docker.nju.edu.cnGCR / GHCR / NGC / Quay推荐支持最全中科大 USTChttps://docker.mirrors.ustc.edu.cnquay.mirrors.ustc.edu.cn、gcr.mirrors.ustc.edu.cn老牌稳定上海交大 SJTUGhttps://docker.mirrors.sjtug.sjtu.edu.cn—校外可用清华大学 TUNAhttps://mirrors.tuna.tsinghua.edu.cn主要做软件包镜像Docker 加速已下线北京外国语大学https://mirrors.bfsu.edu.cn—通用镜像站DaoCloudhttps://docker.m.daocloud.iogcr.m.daocloud.io、ghcr.m.daocloud.io、quay.m.daocloud.io、k8s-gcr.m.daocloud.io、nvcr.m.daocloud.io支持仓库齐全1Panel 镜像https://docker.1panel.live—社区维护毫秒镜像https://docker.hlmirror.com—社区维护4.2 云厂商镜像加速推荐生产环境使用提供方加速地址说明阿里云https://your-id.mirror.aliyuncs.com登录 阿里云容器镜像服务 获取专属地址腾讯云https://mirror.ccs.tencentyun.com仅在腾讯云内网 ECS 加速华为云https://your-id.mirror.swr.myhuaweicloud.com需在控制台开通百度云https://mirror.baidubce.com通用可访问网易https://hub-mirror.c.163.com老牌镜像源京东云https://hub-mirror.jdcloud.com—4.3 多镜像源 daemon.json 配置示例可同时配置多个 mirrorDocker 会按顺序尝试前一个失败自动切换下一个sudotee/etc/docker/daemon.json-EOF { registry-mirrors: [ https://docker.nju.edu.cn, https://docker.mirrors.ustc.edu.cn, https://docker.m.daocloud.io, https://hub-mirror.c.163.com, https://mirror.baidubce.com ] } EOFsudosystemctl daemon-reloadsudosystemctl restartdocker4.4 DaoCloud 多仓库替换对照表DaoCloud 是除南大外唯一支持所有主流海外仓库的国内加速服务原始仓库DaoCloud 镜像docker.iodocker.m.daocloud.iogcr.iogcr.m.daocloud.ioghcr.ioghcr.m.daocloud.iok8s.gcr.iok8s-gcr.m.daocloud.ioregistry.k8s.iok8s.m.daocloud.ionvcr.ionvcr.m.daocloud.ioquay.ioquay.m.daocloud.iomcr.microsoft.commcr.m.daocloud.ioelastic.coelastic.m.daocloud.io4.5 镜像源测速脚本挑选最快的镜像源使用#!/bin/bash# 测试各镜像源连通性与延迟MIRRORS(docker.nju.edu.cndocker.mirrors.ustc.edu.cndocker.m.daocloud.iohub-mirror.c.163.commirror.baidubce.comdocker.1panel.live)formin${MIRRORS[]};doecho-n测试$m... curl-o/dev/null-s-w状态码: %{http_code} 耗时: %{time_total}s\n\--connect-timeout5https://$m/v2/done