Docker 国内镜像配置

由于在国内无法拉取Docker Hub官方仓库镜像,可配置国内镜像,解决Docker镜像拉取失败或缓慢的问题

问题

拉取 Docker 官方镜像时,无法访问镜像地址,或拉取缓慢。

1
error pulling image configuration: download failed after attempts=6: dialing production.cloudflare.docker.com:443 with direct connection: connecting to 69.171.229.73:443: dial tcp 69.171.229.73:443: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.

解决方法

配置 Docker 镜像仓库

编辑文件 /etc/docker/daemon.json,加入以下内容

1
2
3
4
5
6
  "registry-mirrors": [
    "https://docker.m.daocloud.io",
    "https://dockerproxy.com",
    "https://docker.mirrors.ustc.edu.cn",
    "https://docker.nju.edu.cn"
  ]

daemon.json 完整配置如下:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
{
  "builder": {
    "gc": {
      "defaultKeepStorage": "4GB",
      "enabled": true
    }
  },
  "experimental": false,
  "insecure-registries": [
    "192.168.9.30"
  ],
  "registry-mirrors": [
    "https://docker.m.daocloud.io",
    "https://dockerproxy.com",
    "https://docker.mirrors.ustc.edu.cn",
    "https://docker.nju.edu.cn"
  ]
}

重启 Docker 服务

1
2
sudo systemctl daemon-reload
sudo systemctl restart docker

参考

【1】Docker Hub 国内镜像设置方法,解决Docker镜像拉取失败 - ikuai - 博客园 (cnblogs.com)

Licensed under CC BY-NC-SA 4.0
Gear(夕照)的博客。记录开发、生活,以及一些不足为道的思考……