Docker配置国内镜像源
# 25.Docker配置国内镜像源
由于 GFW 的原因,在下载镜像的时候,经常会出现下载失败的情况。此时就可以使用国内的镜像源。
什么是镜像源:简单来说就是某个组织(学校、公司、甚至是个人)先通过某种手段将国外的镜像下载下来,然后上传到国内的网站,这样我们在国内就可以通过这个网站下载到镜像源
# 起因
笔者有一次在构建镜像的时候,发现下载镜像报错了:
failed to do request: Get "https://production.cloudflare.docker.com/registry-v2/docker/registry/v2/blobs/sha256/e7/e7d39d4d8569a6203be5b7a118d4d92526b267087023a49ee0868f7c50190191/data?verify=1717770949-vcXzP%2BxUA2JIB7lugP3KRzgJpZA%3D": dial tcp 108.160.165.53:443: i/o timeout
1
这就是因为 GFW,下载国外镜像的时候超时。
DockerHub官方镜像源(https://hub.docker.com),从去年起就无法正常访问了。
# 常见镜像
- Docker 中国区官方镜像:https://registry.docker-cn.com (opens new window)
- 网易:http://hub-mirror.c.163.com (opens new window)
- ustc:https://docker.mirrors.ustc.edu.cn (opens new window)
# 配置方法
在 /etc/docker/daemon.json 文件(如果没有该文件则新建)里新增配置:
{
"registry-mirrors": [
"http://hub-mirror.c.163.com",
"https://registry.docker-cn.com",
"https://docker.mirrors.ustc.edu.cn"
]
}
1
2
3
4
5
6
7
2
3
4
5
6
7
# 重启与检查
service docker restart
1
# 其他
最近,不少国内的镜像也因为监管下架了,不知道以后 Docker 怎么使用了,唉。
例如,上海交大发出的公告 (opens new window):
随后,南京大学 (opens new window)和中国科技大学 (opens new window)的镜像源也宣布关闭:
目前整理到能用的镜像源如下(不知道以后会不会被封):
{
"registry-mirrors": [
"https://registry.docker-cn.com",
"http://hub-mirror.c.163.com",
"https://dockerhub.azk8s.cn",
"https://mirror.ccs.tencentyun.com",
"https://registry.cn-hangzhou.aliyuncs.com",
"https://docker.mirrors.ustc.edu.cn",
"https://docker.m.daocloud.io",
"https://noohub.ru",
"https://huecker.io",
"https://dockerhub.timeweb.cloud"
]
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15
部分镜像源说明:
- Docker官方镜像(中国区):https://registry.docker-cn.com
- 网易云:http://hub-mirror.c.163.com
- Azure 中国:https://dockerhub.azk8s.cn
- 腾讯云公共镜像: https://mirror.ccs.tencentyun.com
- 阿里云公共镜像: https://registry.cn-hangzhou.aliyuncs.com
- 百度镜像:https://mirror.baidubce.com
在 GitHub 上编辑此页 (opens new window)
上次更新: 2024/6/11 12:50:04