Docker从理论到实践(三)------配置你的DaoCloud的Docker镜像源加速器

关于Docker镜像拉取,由于网络、镜像资源问题,我们想在Docker Hub下载所需镜像,简直很痛苦。。。
除了使用VPN或代理之外,最为有效方式就是使用Docker国内镜像。
DaoCloud是首个提供国内免费Docker Hub镜像的团体,可以使用DaoCloud团队提供的Docker Hub Mirror服务。

附上官网地址:https://www.daocloud.io/mirror

Docker加速器简介

Docker加速器是 DaoCloud 推出的 Docker Hub Mirror 服务的官方名称。
Docker加速器提供Docker Registry(Docker Hub)在中国的镜像代理服务,为中国用户在国内服务器上缓存诸多镜像。
当用户的Docker设定了--registry-mirror参数后,用户的Docker拉取镜像时,首先去Docker加速器中查找镜像,若命中则说明该镜像已经在Docker加速器中缓存,用户直接从Docker加速器中下载。
若没有命中,则说该镜像还没有被缓存,那么Docker加速器首先会被驱使去Docker Hub中下载该镜像,并进行缓存,最终让用户从Docker加速器中下载该镜像。

DaoCloud官网上给出的配置Docker镜像站方式如下:

Docker加速器使用说明

DaoCloud注册并登录。
在登录后的页面(https://dashboard.daocloud.io/),点击“加速器”标签,根据新弹出的页面中“配置 Docker 加速器”信息,更改自己的 Docker 配置文件,然后重启Docker,使之生效。
注意:此时,从“配置 Docker 加速器”信息中,我们其实已经得到一个免费的docker镜像地址,类似于“http://f361db2.m.daocloud.io”。

示例:配置及使用Docker加速器

这里以CentOS系统为例。

Linux
curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://f361db2.m.daocloud.io
该脚本可以将 --registry-mirror 加入到你的Docker配置文件/etc/docker/daemon.json中。
适用于 Ubuntu14.04、Debian、CentOS6 、CentOS7、Fedora、Arch Linux、openSUSE Leap 42.1,其他版本可能有细微不同。

注意:将http://f361db2.m.daocloud.io替换为实际的链接。
更多详情请访问文档

配置Docker加速器

[root@master03 bin]# 
[root@master03 bin]# curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://f1361db2.m.daocloud.io
docker version >= 1.12
{"registry-mirrors": ["http://f1361db2.m.daocloud.io"]}
Success.
You need to restart docker to take effect: sudo systemctl restart docker 
[root@master03 bin]# systemctl daemon-reload
[root@master03 bin]# systemctl restart docker

使用Docker加速器拉取镜像

[root@master03 /]#
 #这里我们还没有镜像
[root@master03 /]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
[root@master03 /]# 
#下载一个ubuntu镜像
[root@master03 /]# docker run -it ubuntu /bin/bash
Unable to find image 'ubuntu:latest' locally
latest: Pulling from library/ubuntu
7413c47ba209: Pull complete 
0fe7e7cbb2e8: Pull complete 
1d425c982345: Pull complete 
344da5c95cec: Pull complete 
Digest: sha256:d417542e2bd7f46f701b55075af41a6b47a736979896c28c0eafa1bafba2e500
Status: Downloaded newer image for ubuntu:latest
#镜像下载完成后,将会进到容器中,如果查看镜像资源,需要exit退出来
root@08ea8b861134:/# 
root@08ea8b861134:/# docker images
bash: docker: command not found
root@08ea8b861134:/# exit
exit
#docker镜像已经下载好了
[root@master03 /]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
ubuntu              latest              3556258649b2        13 days ago         64.2MB
[root@master03 /]# 
原创文章 104 获赞 154 访问量 13万+

猜你喜欢

转载自blog.csdn.net/qq_27706119/article/details/98605179