由于國內訪問直接訪問Docker hub網速比較慢,拉取鏡像的時間就會比較長。一般我們會使用鏡像加速或者直接從國內的一些平臺鏡像倉庫上拉取。
我比較常用的是網易的鏡像中心和daocloud鏡像市場。
網易鏡像中心:https://c.163.com/hub#/m/home/
daocloud鏡像市場:https://hub.daocloud.io/
我們可以先查看下自己的鏡像,使用命令:
[root@localhost docker]# docker images
[root@localhost docker]# docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEdocker.io/nginx latest 6b914bbcb89e 9 days ago 181.8 MBhub.c.163.com/library/nginx latest db079554b4d2 3 weeks ago 181.8 MBdaocloud.io/library/mongo 3.0.14 9fe27000609d 4 weeks ago 269.7 MBhub.c.163.com/library/mysql latest 7666f75adb6b 5 weeks ago 405.6 MBhub.c.163.com/library/ubuntu latest f49eec89601e 6 weeks ago 129.5 MBhub.c.163.com/library/redis latest 45c3ea2cecac 7 weeks ago 182.9 MBhub.c.163.com/library/centos latest c3987965c15d 4 months ago 196.5 MB
然后可以在網易的鏡像中心和daocloud鏡像市場上查詢想要拉取的鏡像。
如圖:網易鏡像
拉取鏡像的命令是:
docker pull 鏡像名字
所以我們可以按照給出的鏡像名字或者命令直接拉取。
[root@localhost docker]# docker pull hub.c.163.com/library/tomcat:latestTrying to pull repository hub.c.163.com/library/tomcat ... latest: Pulling from hub.c.163.com/library/tomcat5040bd298390: 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
[root@localhost docker]# docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEhub.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的。
使用命令
[root@localhost 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給出的命令直接更改(建議使用命令)
更改后重啟docker
service docker restart
然后再拉取鏡像就會發現速度提高好多。
詳情請參考daocloud的說明文檔:http://guide.daocloud.io/dcs/daocloud-9153151.html
docker官方文檔:https://docs.docker.com/engine/admin/
里面有其他版本的修改說明。
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VEVB武林網。
新聞熱點
疑難解答
圖片精選