一、O、前言¶
我们在日常工作或自己搭建环境时,常常需要从Docker Hub上拉取镜像,但是在拉取的过程中,速度很慢很慢... 基于阿里云镜像加速器可以解决上述问题,下面操作适用于ubuntu和centos7,亲测有效!!!
在这里特别感谢阿里云的技术支持!!!
二、获取加速器地址¶
1、点击阿里云镜像加速器官网,打开如下

2、上述官网地址打开后,其实都差不多了。因为细心的人可以发现阿里云已经给出操作文档了。大家按照上面的指示完成相应操作即可。
三、编写daemon.json文件¶
1、执行mkdir -p /etc/docker命令创建存放daemon.json文件的目录
[root@localhost ~]# mkdir -p /etc/docker
2、执行以下语句将语句写入daemon.json文件(没有会自动进行创建)
[root@localhost ~]# tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://y0araofw.mirror.aliyuncs.com"]
}
EOF
3、执行cat /etc/docker/daemon.json命令查看daemon.json配置文件
[root@localhost ~]# cat /etc/docker/daemon.json
{
"registry-mirrors": ["https://y0araofw.mirror.aliyuncs.com"]
}
四、重启docker服务¶
1、执行systemctl daemon-reload命令重新加载daemon.json文件
[root@localhost ~]# systemctl daemon-reload
2、执行systemctl restart docker命令重启docker
[root@localhost ~]# systemctl restart docker
五、检查设置是否生效¶
1、执行docker info命令查看全系统信息,到输出末尾可以查看到网站地址和上述获取的地址一致代表设置已经生效
[root@localhost ~]# docker info
...
...
Insecure Registries:
127.0.0.0/8
Registry Mirrors:
https://y0araofw.mirror.aliyuncs.com/
Live Restore Enabled: false
2、执行docker image pull ubuntu:latest命令再次拉取镜像,观察很快。
[root@localhost ~]# docker image pull ubuntu:latest
latest: Pulling from library/ubuntu
7b1a6ab2e44d: Pull complete
Status: Downloaded newer image for ubuntu:latest
docker.io/library/ubuntu:latest