国内从 Docker Hub 拉取镜像有时会超时,此时可以配置镜像加速器。Docker 官方和国内很多云服务商都提供了国内加速器服务。主要有:

1. Docker官方的中国加速器

2. 阿里云加速器

ps:依旧是Ubuntu16.04版本

配置加速器

在/etc/docker/daemon.json修改以下配置(PS:如果没有此文件,可以新建一个文件,使用touch命令)

配置阿里云加速器

在daemon.json文件中加入:

{
  "registry-mirrors": ["https://ptyvr3tn.mirror.aliyuncs.com"]
}

重新启动Docker

sudo systemctl daemon-reload
sudo systemctl restart docker

配置官方加速器

在daemon.json中加入:

{
  "registry-mirrors": ["https://registry.docker-cn.com"]
}

重新启动docker

sudo systemctl daemon-reload
sudo systemctl restart docker

检测是否配置成功

使用以下命令:

docker info

结果如下:

root@iZwz99z2ljzabken0hvkjrZ:/etc/docker# docker info
Client:
 Debug Mode: false

Server:
 Containers: 3
  Running: 2
  Paused: 0
  Stopped: 1
 Images: 10
 Server Version: 19.03.1
 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: 894b81a4b802e4eb2a91d1ce216b8817763c29fb
 runc version: 425e105d5a03fabd737a126ad93d62a9eeede87f
 init version: fec3683
 Security Options:
  apparmor
  seccomp
   Profile: default
 Kernel Version: 4.4.0-93-generic
 Operating System: Ubuntu 16.04.3 LTS
 OSType: linux
 Architecture: x86_64
 CPUs: 1
 Total Memory: 1.953GiB
 Name: iZwz99z2ljzabken0hvkjrZ
 ID: RGKO:7TY7:7VE5:O745:Z5M6:ZMX4:CKWF:NR2Z:IYPX:5MDA:X4FM:W7TY
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Registry Mirrors:
  https://ptyvr3tn.mirror.aliyuncs.com/
 Live Restore Enabled: false

检查Registry Mirrors:配置是否为之前配置的地址。如果是则表示配置成功。