雲計算:Docker安裝及本地鏡像倉庫配置
實驗環境:
OS:CentOS7.0 -X64
上網環境:通過代理服務器上網
1.首先下載docker安裝包docker-engine-1.7.1-1.el7.centos.x86_64.rpm
安裝包下載地址:
https://get.docker.com/rpm/1.7.1/centos-7/RPMS/x86_64/docker-engine-1.7.1-1.el7.centos.x86_64.rpm[root@docker ~]# rpm -ivh docker-engine-1.7.1-1.el7.centos.x86_64.rpm #安裝docker包
[root@docker ~]# service docker start #啟動docker服務
Starting docker (via systemctl): [ OK ]
[root@docker ~]# docker ps #查看docker驅動的進程,目前暫時沒有驅動進程
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[root@docker ~]# docker images #查看docker鏡像文件,初始安裝沒有鏡像
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
2.配置服務器代理上網:由於上網環境是通過代理上網,所以本臺測試機器需要配置代理才可以上網。
配置方法如下:編輯/etc/profile 添加以下內容
http_proxy=192.168.1.100:8005 #根據實際情況設定自己的代理服務器
https_proxy=$http_proxy
http_proxy_username=test #如果代理需要通過用戶名和密碼驗證則設置,如果不需要驗證username和password則可以不設定。
http_proxy_password=12356
no_proxy=192.*.*.*,*.local,localhost,127.0.0.1 #設定不需要代理的ip
[root@docker ~]# ping baidu.com #測試ping百度,連接成功,配置外網代理成功。
PING baidu.com (220.181.57.216) 56(84) bytes of data.
64 bytes from 220.181.57.216 (220.181.57.216): icmp_seq=1 ttl=51 time=30.7 ms
64 bytes from 220.181.57.216 (220.181.57.216): icmp_seq=2 ttl=51 time=33.4 ms
64 bytes from 220.181.57.216 (220.181.57.216): icmp_seq=3 ttl=51 time=34.0 ms
以為通過上述設定就可以通過 docker pull [images名稱] 下載docker鏡像文件,結果報以下錯誤:
[root@docker ~]# docker pull daocloud.io/library/node:8.1.0-slim #通過pull命令,提示的報錯,反正我也沒看懂,所以就網上搜索
一下,找了很多方法,總算找到了原因,是由於docker需要再單獨配置代理上網。
Error response from daemon: invalid registry endpoint https://daocloud.io/v0/: unable to ping registry endpoint https://daocloud.io/v0/
v2 ping attempt failed with error: Get https://daocloud.io/v2/: remote error: handshake failure
v1 ping attempt failed with error: Get https://daocloud.io/v1/_ping: remote error: handshake failure. If this private registry supports only HTTP or HTTPS with an unknown CA certificate, please add `--insecure-registry daocloud.io` to the daemon's arguments. In the case of HTTPS, if you have access to the registry's CA certificate, no need for the flag; simply place the CA certificate at /etc/docker/certs.d/daocloud.io/ca.crt
3.配置docker代理上網,新增以下配置文件
[root@docker ~]# vim /etc/systemd/system/docker.service.d/http-proxy.conf #新增代理配置文件,內容如下:
[Service]
Environment="HTTP_PROXY=10.109.134.247:8005"
Environment="NO_PROXY=localhost,127.0.0.0/8,docker-registry.somecorporation.com"
保存退出,再次使用pull命令下載成功,可以使用pull命令下載鏡像了,總算搞定了。
[root@docker ~]# docker images #查看docker鏡像文件,初始安裝沒有鏡像
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
[root@docker ~]# docker pull busybox #通過pull下載busybox鏡像到本地鏡像倉庫。
latest: Pulling from busybox
f9ea5e501ad7: Pull complete
ac3f08b78d4e: Pull complete
Digest: sha256:da268b65d710e5ca91271f161d0ff078dc63930bbd6baac88d21b20d23b427ec
Status: Downloaded newer image for busybox:latest #下載busybox鏡像成功
[root@docker docker]# docker pull daocloud.io/library/nginx:latest #下載nginx鏡像成功
latest: Pulling from daocloud.io/library/nginx
2cd56ba950c8: Pull complete
8ecf8a9b915f: Pull complete
2f035d3cb1ca: Pull complete
33ff728209b6: Pull complete
a8788126754a: Pull complete
534bc4991cb2: Pull complete
4eff2ba6990a: Pull complete
ca14437b52c6: Pull complete
64d6b4f35a10: Pull complete
476b0368435b: Pull complete
Digest: sha256:cb29ee85b234f356fb8a77d8cfb78b42355f7f016f528f11a2a5f75e4862dc94
Status: Downloaded newer image for daocloud.io/library/nginx:latest
[root@docker docker]# docker images #再次查看本地鏡像倉庫,已經有2個剛下載的鏡像。
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
daocloud.io/library/nginx latest 476b0368435b 7 days ago 108.9 MB
busybox latest ac3f08b78d4e 12 days ago 1.146 MB
雲計算:Docker安裝及本地鏡像倉庫配置