51工具盒子

依楼听风雨
笑看云卷云舒,淡观潮起潮落

加速docker镜像下载速度

# 加速 docker 镜像下载速度 {#加速-docker-镜像下载速度}

本文讲解如何加速 docker 镜像的下载速度。默认情况下 docker 镜像是从官网下载,有些慢,那么我们可以通过配置国内的镜像地址,来加速镜像的下载速度。常用的国内镜像地址有阿里云、网易、七牛云。

注意: 要求 Docker 客户端版本 > 1.10.0

# 1. 准备镜像地址 {#_1-准备镜像地址}

  • 网易
    http://hub-mirror.c.163.com
  • 阿里云
    https://<你的 ID>.mirror.aliyuncs.com
    登录阿里云平台,访问地址https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors即可看到专属加速地址
  • 七牛云
    https://reg-mirror.qiniu.com
  • docker中国 https://registry.docker-cn.com
  • 中科大 http://docker.mirrors.ustc.edu.cn

# 2. 配置镜像地址 {#_2-配置镜像地址}

编辑配置文件/etc/docker/daemon.json, 配置镜像地址:

sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://iuq5x200.mirror.aliyuncs.com", "https://registry.docker-cn.com", "http://docker.mirrors.ustc.edu.cn", "http://hub-mirror.c.163.com"]
}
EOF

镜像地址可以配置多个。

# 3. 重启 docker 服务 {#_3-重启-docker-服务}

需要重启 docker 服务,镜像地址的配置才会生效。执行如下命令重启 docker 服务:

[root@VM-0-6-centos dockerfile]# systemctl daemon-reload                              
[root@VM-0-6-centos dockerfile]# systemctl restart docker
[root@VM-0-6-centos dockerfile]#

# 4. 验证 {#_4-验证}

执行 docker info 可以查看加速镜像地址是否已生效。
验证过程如下:

[root@VM-0-6-centos mysql]# docker info
Client:
 Debug Mode: false

Server:
 Containers: 1
  Running: 1
  Paused: 0
  Stopped: 0
 Images: 30
 Server Version: 19.03.13
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: true
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 8fba4e9a7d01810a393d5d25a3621dc101981175
 runc version: dc9208a3303feef5b3839f4323d9beb36df0a9dd
 init version: fec3683
 Security Options:
  seccomp
   Profile: default
 Kernel Version: 4.18.0-193.6.3.el8_2.x86_64
 Operating System: CentOS Linux 8 (Core)
 OSType: linux
 Architecture: x86_64
 CPUs: 2
 Total Memory: 3.69GiB
 Name: VM-0-6-centos
 ID: QNXQ:J3EK:5AWG:JNJK:UU4G:AVKL:LYD4:N5JO:NUUD:6AZV:YO7H:GMLY
 Docker Root Dir: /data/docker/storage
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

[root@VM-0-6-centos mysql]# systemctl restart docker
[root@VM-0-6-centos mysql]# docker info
Client:
 Debug Mode: false

Server:
 Containers: 1
  Running: 1
  Paused: 0
  Stopped: 0
 Images: 30
 Server Version: 19.03.13
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: true
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 8fba4e9a7d01810a393d5d25a3621dc101981175
 runc version: dc9208a3303feef5b3839f4323d9beb36df0a9dd
 init version: fec3683
 Security Options:
  seccomp
   Profile: default
 Kernel Version: 4.18.0-193.6.3.el8_2.x86_64
 Operating System: CentOS Linux 8 (Core)
 OSType: linux
 Architecture: x86_64
 CPUs: 2
 Total Memory: 3.69GiB
 Name: VM-0-6-centos
 ID: QNXQ:J3EK:5AWG:JNJK:UU4G:AVKL:LYD4:N5JO:NUUD:6AZV:YO7H:GMLY
 Docker Root Dir: /data/docker/storage
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Registry Mirrors:
  https://reg-mirror.qiniu.com/
 Live Restore Enabled: false

[root@VM-0-6-centos mysql]#

可以看出, docker 镜像加速地址已经配置完毕。

# 5. 下载 docker 镜像 {#_5-下载-docker-镜像}

可以使用docker pull下载 docker 镜像了。

赞(4)
未经允许不得转载:工具盒子 » 加速docker镜像下载速度