Centos7.0 配置docker 映象加速

YatHo發表於2017-11-20

在Docker Hub官網上註冊帳號,即可下載使用倉庫裡的全部的docker映象。而因為網路原因,國內的開發者沒辦法流暢的下載映象,經常會出現下載中斷的錯誤。解決方法就是使用國內的容器Hub加速服務,本質就是更改pull優先順序較高的伺服器為國內的站點。

公司下載映象實在太慢,無語了只能換映象加速地址了。

 

國內docker映象加速站

系統環境

作業系統: CentOS 7 
docker版本: 1.9.1

[root@vm-50-151 docker]# cat /etc/redhat-release 
CentOS Linux release 7.4.1708 (Core) 
[root@vm-50-151 docker]# docker version
Client:
 Version:         1.12.6
 API version:     1.24
 Package version: docker-1.12.6-61.git85d7426.el7.centos.x86_64
 Go version:      go1.8.3
 Git commit:      85d7426/1.12.6
 Built:           Tue Oct 24 15:40:21 2017
 OS/Arch:         linux/amd64

Server:
 Version:         1.12.6
 API version:     1.24
 Package version: docker-1.12.6-61.git85d7426.el7.centos.x86_64
 Go version:      go1.8.3
 Git commit:      85d7426/1.12.6
 Built:           Tue Oct 24 15:40:21 2017
 OS/Arch:         linux/amd64

  

DaoCloud加速

  http://guide.daocloud.io/dcs/daocloud-9153151.html

  DaoCloud現在是提供一個一鍵指令碼配置registry-mirror,這尼瑪有坑,配了後我就啟動不了服務了。

[root@vm-50-151 docker]# service docker restart
Redirecting to /bin/systemctl restart docker.service
Job for docker.service failed because the control process exited with error code. See "systemctl status docker.service" and "journalctl -xe" for details.
[root@vm-50-151 docker]# systemctl status docker.service
?.docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Mon 2017-11-20 10:59:29 CST; 6s ago
     Docs: http://docs.docker.com
  Process: 11986 ExecStart=/usr/bin/dockerd-current --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 $REGISTRIES (code=exited, status=1/FAILURE)
 Main PID: 11986 (code=exited, status=1/FAILURE)

Nov 20 10:59:29 vm-50-151 systemd[1]: Starting Docker Application Container Engine...
Nov 20 10:59:29 vm-50-151 dockerd-current[11986]: time="2017-11-20T10:59:29+08:00" level=fatal msg="unable to configure the Docker daemon with file /etc/docker/daemon.json: invalid character '}' loo... key string\n"
Nov 20 10:59:29 vm-50-151 systemd[1]: docker.service: main process exited, code=exited, status=1/FAILURE
Nov 20 10:59:29 vm-50-151 systemd[1]: Failed to start Docker Application Container Engine.
Nov 20 10:59:29 vm-50-151 systemd[1]: Unit docker.service entered failed state.
Nov 20 10:59:29 vm-50-151 systemd[1]: docker.service failed.
Hint: Some lines were ellipsized, use -l to show in full.

  測試後發現,是/etc/docker/daemon.json 檔案李的json格式存在問題,直接手動修改

vi  /etc/docker/daemon.json

  修改後

[root@vm-50-151 docker]# cat  /etc/docker/daemon.json
{
    "registry-mirrors": [
       "http://9aba2c9f.m.daocloud.io"
    ],
    "insecure-registries": []
}

  重啟伺服器

[root@vm-50-151 docker]# service docker restart
Redirecting to /bin/systemctl restart docker.service

  搜尋映象

[root@vm-50-151 docker]# docker search mysql
INDEX       NAME                                                             DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
docker.io   docker.io/mysql                                                  MySQL is a widely used, open-source relati...   5249      [OK]       
docker.io   docker.io/mariadb                                                MariaDB is a community-developed fork of M...   1628      [OK]       
docker.io   docker.io/mysql/mysql-server                                     Optimized MySQL Server Docker images. Crea...   367                  [OK]
docker.io   docker.io/percona                                                Percona Server is a fork of the MySQL rela...   301       [OK]       

  經過使用測試:下載docker映象時不再出現下載失敗提示,粗略估計下載速度在200k/s左右,基本滿足使用需求。

相關文章