Docker - 配置DaoCloud的Docker加速器


由於眾所周知的原因,從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 ~]# 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM