anliven

由于众所周知的原因,从Docker Hub难以高效地下载镜像。
除了使用VPN或代理之外,最为有效的方式就是使用Docker国内镜像。
DaoCloud是首个提供国内免费Docker Hub镜像的团体,可以使用DaoCloud团队提供的Docker Hub Mirror服务。

Docker加速器简介

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

Docker加速器使用说明

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

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

这里以Linux系统为例。

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

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

配置Docker加速器

[root@CentOS-7 ~]# uname -a 
Linux CentOS-7 3.10.0-327.el7.x86_64 #1 SMP Thu Nov 19 22:10:57 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
[root@CentOS-7 ~]# 
[root@CentOS-7 ~]# cat /etc/redhat-release 
CentOS Linux release 7.2.1511 (Core) 
[root@CentOS-7 ~]# 
[root@CentOS-7 ~]# curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://abcd1234.m.daocloud.io
Success.
You need to restart docker to take effect: sudo systemctl restart docker 
[root@CentOS-7 ~]# 
[root@CentOS-7 ~]# systemctl restart docker
[root@CentOS-7 ~]# 

使用Docker加速器拉取镜像

[root@CentOS-7 ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
[root@CentOS-7 ~]# 
[root@CentOS-7 ~]# docker run ubuntu
Unable to find image \'ubuntu:latest\' locally
Trying to pull repository docker.io/library/ubuntu ... 
latest: Pulling from docker.io/library/ubuntu
b3e1c725a85f: Pull complete 
4daad8bdde31: Pull complete 
63fe8c0068a8: Pull complete 
4a70713c436f: Pull complete 
bd842a2105a8: Pull complete 
Digest: sha256:dbe36a89ad8daf8bbd2a68f14eab18b969d3f125104da51df6337bbf08d1c8ae
Status: Downloaded newer image for docker.io/ubuntu:latest
[root@CentOS-7 ~]# 
[root@CentOS-7 ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
docker.io/ubuntu    latest              104bec311bcd        8 days ago          128.9 MB
[root@CentOS-7 ~]# 

分类:

技术点:

相关文章:

  • 2019-07-03
  • 2021-11-12
  • 2021-11-12
  • 2021-12-05
  • 2021-12-15
  • 2019-11-06
  • 2021-05-08
  • 2021-12-15
猜你喜欢
  • 2021-12-02
  • 2018-09-20
  • 2021-04-16
  • 2021-10-08
  • 2021-10-09
  • 2021-11-12
  • 2021-11-12
相关资源
相似解决方案