1. 程式人生 > >docker國內映象拉取和映象加速registry-mirrors配置修改

docker國內映象拉取和映象加速registry-mirrors配置修改

由於國內訪問直接訪問docker hub網速比較慢,拉取映象的時間就會比較長。一般我們會使用映象加速或者直接從國內的一些平臺映象倉庫上拉取。
我比較常用的是網易的映象中心和daocloud映象市場。
網易映象中心:https://c.163.com/hub#/m/home/
daocloud映象市場:https://hub.daocloud.io/

我們可以先檢視下自己的映象,使用命令:
[[email protected] docker]# docker images

[[email protected] docker]# docker images
REPOSITORY                     TAG                 IMAGE ID            CREATED             SIZE
docker.io
/nginx latest 6b914bbcb89e 9 days ago 181.8 MB hub.c.163.com/library/nginx latest db079554b4d2 3 weeks ago 181.8 MB daocloud.io/library/mongo 3.0.14 9fe27000609d 4 weeks ago 269.7 MB hub.c.163.com/library/mysql latest 7666
f75adb6b 5 weeks ago 405.6 MB hub.c.163.com/library/ubuntu latest f49eec89601e 6 weeks ago 129.5 MB hub.c.163.com/library/redis latest 45c3ea2cecac 7 weeks ago 182.9 MB hub.c.163.com/library/centos latest c3987965c15d 4
months ago 196.5 MB

然後可以在網易的映象中心和daocloud映象市場上查詢想要拉取的映象。
如圖:網易映象
DaoCloud

拉取映象的命令是:

docker pull 映象名字

所以我們可以按照給出的映象名字或者命令直接拉取。

[[email protected] docker]# docker pull hub.c.163.com/library/tomcat:latest
Trying to pull repository hub.c.163.com/library/tomcat ... 
latest: Pulling from hub.c.163.com/library/tomcat
5040bd298390: Already exists 
fce5728aad85: Pull complete 
c42794440453: Pull complete 
9789263043d1: Pull complete 
6c6ea13aad15: Pull complete 
55336e5423a8: Pull complete 
228d33a53bdd: Pull complete 
3a1cfabb401c: Pull complete 
b5f79327b275: Pull complete 
bcbb902619eb: Pull complete 
ad3d36b3fbaa: Pull complete 
Digest: sha256:c3a1781843b319547da95c02c3d4c5a428059702fe17d01005093f4dd4f1b87c
[[email protected] docker]# docker images
REPOSITORY                     TAG                 IMAGE ID            CREATED             SIZE
hub.c.163.com/library/tomcat   latest              99765a0d7f44        2 weeks ago         355.3 MB

以上是從國內映象倉庫拉取映象的方法。

如果說還是想從dockerhub上拉取,那麼使用加速器修改docker的registry-mirrors。我這裡使用的是DaoCloud的加速器。
首先在http://www.daocloud.io/進行註冊登入。然後點選加速器。
這裡寫圖片描述
就可以獲取加速器的相關配置。
這裡寫圖片描述
由於docker的版本不同和作業系統。使用的方法也有差異。我這裡使用的是centos7.2和docker1.12的。
使用命令
[[email protected] docker]# docker version

[root@localhost etc]# cat /etc/redhat-release 
CentOS Linux release 7.2.1511 (Core)

在使用daocloud加速器時,上面有說明文件。
所以剛開始我在尋找/etc/default/docker這個配置檔案,一直找不到,後來發現是因為系統和版本的差異。
在centos7上這個配置檔案已經被更改為 /etc/docker/daemon.json
可以在這個配置中新增相應的registry-mirrors路徑
原來是這樣:

[root@localhost docker]# cat daemon.json 
{
    "live-restore": true
}

新增後:

{
    "registry-mirrors": ["http://ef017c13.m.daocloud.io"],
    "live-restore": true
}

可以手動vim新增,也可以使用daocloud給出的命令直接更改(建議使用命令)

[root@localhost docker]# curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://ef017c13.m.daocloud.io

更改後重啟docker

service docker restart