Contents

由于国内访问docker hub的网速太慢,以至于连docker镜像都pull不下来。所以国内的大公司建了一些自己的docker hub和镜像加速器来帮助大家更好的使用docker。
建议:如果你的服务器的网速能够从docker hub上pull下来镜像,就不要用阿里云的镜像加速器。因为他们那随心所欲的文档,完全是在浪费用户的时间和消磨用户的耐心,如果你按照官方文档来做,肯定搞不成。

官方文档这样说:
如何使用Docker加速器
针对Docker客户端版本大于1.10的用户
您可以通过修改daemon配置文件/etc/docker/daemon.json来使用加速器:

1
2
3
4
5
6
7
8
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://ed3ztp0d.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

按照官方文档来做,修改好配置文件后,重启docker,结果报错,提示查看状态:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[root@bogon docker]# systemctl restart docker
Job for docker.service failed because the control process exited with error code. See "systemctl status docker.service" and "journalctl -xe" for details.
[root@bogon docker]# systemctl status docker.service
● docker.service - Docker Application Container Engine
Loaded: loaded (/etc/systemd/system/docker.service; disabled; vendor preset: disabled)
Active: failed (Result: exit-code) since 四 2017-07-20 16:10:04 CST; 12s ago
Docs: http://docs.docker.com
Process: 42330 ExecStart=/usr/bin/dockerd --add-runtime docker-runc=/usr/libexec/docker/docker-runc-current --default-runtime=docker-runc --exec-opt native.cgroupdriver=systemd --userland-proxy-path=/usr/libexec/docker/docker-proxy-current $OPTIONS $DOCKER_STORAGE_OPTIONS $DOCKER_NETWORK_OPTIONS $ADD_REGISTRY $BLOCK_REGISTRY $INSECURE_REGISTRY (code=exited, status=1/FAILURE)
Main PID: 42330 (code=exited, status=1/FAILURE)
7月 20 16:10:04 bogon systemd[1]: Starting Docker Application Container Engine...
7月 20 16:10:04 bogon dockerd[42330]: time="2017-07-20T16:10:04+08:00" level=fatal msg="unable to configure the Docker daemon with file /etc/docker/daemon.json: the following directives are specifi...
7月 20 16:10:04 bogon systemd[1]: docker.service: main process exited, code=exited, status=1/FAILURE
7月 20 16:10:04 bogon systemd[1]: Failed to start Docker Application Container Engine.
7月 20 16:10:04 bogon systemd[1]: Unit docker.service entered failed state.
7月 20 16:10:04 bogon systemd[1]: docker.service failed.
Hint: Some lines were ellipsized, use -l to show in full.

错误中提示,“unable to configure the Docker daemon with file /etc/docker/daemon.json: the following directives are specifi…”,就是刚才修改配置文件导致的问题。
只能去网上搜一下这是啥问题,有人提出了一个办法,编辑

vim /etc/sysconfig/docker

然后OPTIONS=’–selinux-enabled –log-driver=journald –registry-mirror=https://xxxx.mirror.aliyuncs.com‘ ,registry-mirror就是你的镜像加速器地址。
如果这时你再重启docker,还会报那个错误。
但是如果删除了刚配置的daemon.json,就成功了。查看启动参数也带了加速镜像地址:

ps aux | grep docker

然后,还有人提出了一种解决办法,编辑:

vim /etc/systemd/system/docker.service

1
2
3
4
5
6
7
8
9
10
11
12
ExecStart=/usr/bin/dockerd \
--registry-mirror=https://ed3ztp0d.mirror.aliyuncs.com \
--add-runtime docker-runc=/usr/libexec/docker/docker-runc-current \
--default-runtime=docker-runc \
--exec-opt native.cgroupdriver=systemd \
--userland-proxy-path=/usr/libexec/docker/docker-proxy-current \
$OPTIONS \
$DOCKER_STORAGE_OPTIONS \
$DOCKER_NETWORK_OPTIONS \
$ADD_REGISTRY \
$BLOCK_REGISTRY \
$INSECURE_REGISTRY

ExecStart=/usr/bin/dockerd 的下面一行增加了你的registry-mirror,再重启docker,也成功了,反正就是只有按照阿里云的官方文档操作不成功。

Contents