# **Docker的安装及如何配置从国内镜像中拖取需要的images到本地使用**
实验环境:
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
[[email protected] ~]# rpm -ivh docker-engine-1.7.1-1.el7.centos.x86_64.rpm #安装docker包
[[email protected] ~]# service docker start #启动docker服务
Starting docker (via systemctl): [ OK ]
[[email protected] ~]# docker ps #查看docker驱动的进程,目前暂时没有驱动进程
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[[email protected] ~]# 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
[[email protected] ~]# 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镜像文件,结果报以下错误:
[[email protected] ~]# 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代理上网,新增以下配置文件
[[email protected] ~]# 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命令下载镜像了,总算搞定了。
[[email protected] ~]# docker images #查看docker镜像文件,初始安装没有镜像
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
[[email protected] ~]# 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镜像成功
[[email protected] 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
[[email protected] 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
原文地址:http://blog.51cto.com/woyaoxuelinux/2104914