# **Docker的安裝及如何配置從國內鏡像中拖取須要的images到本地使用**node
實驗環境:python
OS:CentOS7.0 -X64linux
上網環境:經過代理服務器上網nginx
1.首先下載docker安裝包docker
下載docker安裝所需的插件:vim
docker-engine-selinux-1.9.1-1.e17.centos.noarch.rpmcentos
下載地址:http://yum.dockerproject.org/repo/main/centos/7/Packages/服務器
docker-engine-1.9.1.1.e17.centos.x86_64.rpmapp
下載地址:http://yum.dockerproject.org/repo/main/centos/7/Packages/ ide
2.安裝docker
先查看下載下來的安裝包:
[root@docker docker]# pwd
/docker
[root@docker docker]# ls
docker-engine-1.9.1-1.el7.centos.x86_64.rpm docker-engine-selinux-1.9.1-1.el7.centos.noarch.rpm
[root@docker docker]# rpm -ivh docker-engine*
warning: docker-engine-1.9.1-1.el7.centos.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID 2c52609d: NOKEY
error: Failed dependencies:
policycoreutils-python is needed by docker-engine-selinux-1.9.1-1.el7.centos.noarch
安裝提示缺乏policycoreutils-python組件
[root@docker docker]# yum install -y policycoreutils-python (經過光盤yum源就能夠直接安裝該組件)
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package policycoreutils-python.x86_64 0:2.5-17.1.el7 will be installed
--> Processing Dependency: setools-libs >= 3.3.8-1 for package: policycoreutils-python-2.5-17.1.el7.x86_64
--> Processing Dependency: libsemanage-python >= 2.5-5 for package: policycoreutils-python-2.5-17.1.el7.x86_64
--> Processing Dependency: audit-libs-python >= 2.1.3-4 for package: policycoreutils-python-2.5-17.1.el7.x86_64
--> Processing Dependency: python-IPy for package: policycoreutils-python-2.5-17.1.el7.x86_64
--> Processing Dependency: libqpol.so.1(VERS_1.4)(64bit) for package: policycoreutils-python-2.5-17.1.el7.x86_64
--> Processing Dependency: libqpol.so.1(VERS_1.2)(64bit) for package: policycoreutils-python-2.5-17.1.el7.x86_64
--> Processing Dependency: libapol.so.4(VERS_4.0)(64bit) for package: policycoreutils-python-2.5-17.1.el7.x86_64
--> Processing Dependency: checkpolicy for package: policycoreutils-python-2.5-17.1.el7.x86_64
--> Processing Dependency: libqpol.so.1()(64bit) for package: policycoreutils-python-2.5-17.1.el7.x86_64
--> Processing Dependency: libapol.so.4()(64bit) for package: policycoreutils-python-2.5-17.1.el7.x86_64
--> Running transaction check
---> Package audit-libs-python.x86_64 0:2.7.6-3.el7 will be installed
---> Package checkpolicy.x86_64 0:2.5-4.el7 will be installed
---> Package libsemanage-python.x86_64 0:2.5-8.el7 will be installed
---> Package python-IPy.noarch 0:0.75-6.el7 will be installed
---> Package setools-libs.x86_64 0:3.3.8-1.1.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
==================================================================================================================
Package Arch Version Repository Size
==================================================================================================================
Installing:
policycoreutils-python x86_64 2.5-17.1.el7 c7-media 446 k
Installing for dependencies:
audit-libs-python x86_64 2.7.6-3.el7 c7-media 73 k
checkpolicy x86_64 2.5-4.el7 c7-media 290 k
libsemanage-python x86_64 2.5-8.el7 c7-media 104 k
python-IPy noarch 0.75-6.el7 c7-media 32 k
setools-libs x86_64 3.3.8-1.1.el7 c7-media 612 k
Transaction Summary
==================================================================================================================
Install 1 Package (+5 Dependent packages)
Total download size: 1.5 M
Installed size: 5.0 M
Downloading packages:
------------------------------------------------------------------------------------------------------------------
Total 4.8 MB/s | 1.5 MB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : checkpolicy-2.5-4.el7.x86_64 1/6
Installing : setools-libs-3.3.8-1.1.el7.x86_64 2/6
Installing : python-IPy-0.75-6.el7.noarch 3/6
Installing : audit-libs-python-2.7.6-3.el7.x86_64 4/6
Installing : libsemanage-python-2.5-8.el7.x86_64 5/6
Installing : policycoreutils-python-2.5-17.1.el7.x86_64 6/6
Verifying : libsemanage-python-2.5-8.el7.x86_64 1/6
Verifying : audit-libs-python-2.7.6-3.el7.x86_64 2/6
Verifying : python-IPy-0.75-6.el7.noarch 3/6
Verifying : policycoreutils-python-2.5-17.1.el7.x86_64 4/6
Verifying : setools-libs-3.3.8-1.1.el7.x86_64 5/6
Verifying : checkpolicy-2.5-4.el7.x86_64 6/6
Installed:
policycoreutils-python.x86_64 0:2.5-17.1.el7
Dependency Installed:
audit-libs-python.x86_64 0:2.7.6-3.el7 checkpolicy.x86_64 0:2.5-4.el7
libsemanage-python.x86_64 0:2.5-8.el7 python-IPy.noarch 0:0.75-6.el7
setools-libs.x86_64 0:3.3.8-1.1.el7
Complete!
[root@docker docker]# rpm -ivh docker-engine* 再次安裝docker,成功安裝
warning: docker-engine-1.9.1-1.el7.centos.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID 2c52609d: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:docker-engine-selinux-1.9.1-1.el7################################# [ 50%]
Re-declaration of type docker_t
Failed to create node
Bad type declaration at /etc/selinux/targeted/tmp/modules/400/docker/cil:1
/usr/sbin/semodule: Failed!
2:docker-engine-1.9.1-1.el7.centos ################################# [100%]
[root@docker docker]# systemctl enable docker.service 設置系統開機自動啓動服務
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
[root@docker docker]# service docker start 啓動服務
Redirecting to /bin/systemctl start docker.service
[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 ~]# systemctl daemon-reload #從新加載daemon
[root@docker ~]# systemctl show docker --property Environment #查看設置的代理環境是否成功。
Environment=HTTP_PROXY=192.168.1.100:8005 NO_PROXY=localhost,127.0.0.0/8,docker-registry.somecorporation.com
[root@docker ~]# systemctl restart docker #或者直接service docker restart 重啓docker服務。
Starting docker (via systemctl): [ OK ]
[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
順便提供國內鏡像地址: