漫谈Docker容器手艺(二):打造SDN容器百宝箱_加密

日期:2015-01-26 / 人气: / 来源:网络

按照上篇 《打造SDN容器百宝箱(一)》的想法,构建一个类似于CDSC(container define service cloud)平台的CaaS服务,实现灵活可伸缩的弹性容器云。作为企业内部的容器云平台,第一步就是搭建自己的私有容器registry。

在2014年12月8、9号的“中国未来网络发展与创新论坛暨全球SDN开放网络高峰会议”上,国内道里云公司已经利用openstack Docker技术组合,提供了跨数据中心的“小云”服务,从用户视角提出了“租户控制器”理念。个人认为,这体现了道里云对云和SDN的理解既务实又灵活,没有困死在SDN的学术定义中,也没有“累死”在打造openstack的无敌航母上。话不罗嗦了,这次主要写如何搭建Docker私有仓库及相关细节注意事项。

1 安装环境

此环境搭建主要在Ubuntu14.04系统上进行:

Shell $ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 14.04.1 LTS Release: 14.04 Codename: trusty
123456 $ lsb_release -aNo LSB modules are available.Distributor ID: UbuntuDescription: Ubuntu 14.04.1 LTSRelease: 14.04Codename: trusty

2 安装方法及步骤

1.从github上下载docker-registry源码

Shell sudo git clone https://github.com/dotcloud/docker-registry
1 sudo git clone https://github.com/dotcloud/docker-registry

2.安装环境依赖库

Shell sudo apt-get install build-essential python-dev libevent-dev python-pip libssl-dev liblzma-dev libffi-dev gunicorn
1 sudo apt-get install build-essential python-dev libevent-dev python-pip libssl-dev liblzma-dev libffi-dev gunicorn

3.配置config

Shell cd docker-registry/config sudo cp config_sample.yml config.yml sudo vi config.yml3. ##配置config cd docker-registry/config sudo cp config_sample.yml config.yml
12345 cd docker-registry/config sudo cp config_sample.yml config.yml sudo vi config.yml3.  ##配置config cd docker-registry/config sudo cp config_sample.yml config.yml

修改配置文件:

Shell $sudo vi config.yml local: &local <<: *common storage: local storage_path: _env:STORAGE_PATH:/tmp/registry
12345 $sudo vi config.ymllocal: &local<<: *commonstorage: localstorage_path: _env:STORAGE_PATH:/tmp/registry

安装Docker需为本地自定义路径/home/dockertest/registry

Shell mkdir /home/dockertest/registry
1 mkdir  /home/dockertest/registry

4.安装docker-registry依赖

Shell cd docker-registry sudo pip install .
12 cd docker-registrysudo pip install .

5.启动服务

Shell sudo gunicorn --access-logfile - --debug -k gevent -b 0.0.0.0:5000 -w 1 docker_registry.wsgi:application
1 sudo gunicorn --access-logfile - --debug -k gevent -b 0.0.0.0:5000 -w 1 docker_registry.wsgi:application

Gunicorn是一个Python WSGI UNIX的HTTP服务器,gunicorn,配合Apache或Nginx,可以实现简单高效的python web的应用部署和维护。

6.验证

Shell curl http://192.168.5.31:5000
1 curl http://192.168.5.31:5000

输出为:""docker-registry server"",搭建成功!

3 测试

3.1 上传镜像

由于我在本地已经做好了floodlight的image,现在需要把floodlight的image(ID为1bd7e4dda917 ) push到刚刚创建docker-registry里。

(1)创建别名

Shell sudo docker tag 1bd7e4dda917 192.168.5.31:5000/uspeed_sdnpool/floodlight
1 sudo docker tag 1bd7e4dda917 192.168.5.31:5000/uspeed_sdnpool/floodlight

(2)上传镜像

Shell sudo docker push 192.168.5.31:5000/uspeed_sdnpool/floodlight
1 sudo docker push 192.168.5.31:5000/uspeed_sdnpool/floodlight

在上传镜像的过程中发生一个错误:
2015/01/14 16:25:47 Error: Invalid registry endpoint https://192.168.5.31:5000/v1/: Missing certificate ca.cert for key ca.key. If this private registry supports only HTTP or HTTPS with an unknown CA certificate, please add --insecure-registry 192.168.5.31:5000 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/192.168.5.31:5000/ca.crt
解决方法:
这个问题是由于Docker1.3增加了安全认证的功能,根据提示需要在启动docker守护进程时,增加--insecure-registry 192.168.5.31:5000选项。
通过ps -ef | grep docker获得docker的守护进程ID,通过kill -9杀死。

重新启动docker

Shell sudo /usr/bin/docker --insecure-registry 192.168.5.31:5000 �Cd
1 sudo /usr/bin/docker  --insecure-registry 192.168.5.31:5000 �Cd

问题解决后重新上传镜像:

Shell sudo docker push 192.168.5.31:5000/uspeed_sdnpool/floodlight
1 sudo docker push 192.168.5.31:5000/uspeed_sdnpool/floodlight

3.2 查询镜像

可以通过curl http://192.168.5.31:5000/v1/search查看刚刚的image

3.3 下载镜像

Shell sudo docker pull 192.168.5.31:5000/uspeed_sdnpool/floodlight
1 sudo docker pull 192.168.5.31:5000/uspeed_sdnpool/floodlight

3.4 运行floodlight容器

Shell sudo docker run -t -i -p 192.168.5.31:8080:8080 --name floodlight 192.168.5.31:5000/uspeed_sdnpool/floodlight:latest /bin/bash
1 sudo docker run -t -i -p 192.168.5.31:8080:8080 --name floodlight  192.168.5.31:5000/uspeed_sdnpool/floodlight:latest /bin/bash

-p表示floodlight容器的8080端口映射到192.168.5.31本机的8080端口
--name表示启动的容器别名,后面是镜像名
-t -i表示创建容器后开辟一个交互式操作终端

进入容器后,执行Floodlight控制器启动命令:

Shell java -jar /floodlight/floodlight.jar
1 java -jar /floodlight/floodlight.jar

在宿主机访问floodlight的Web url界面:http://192.168.5.31:8080/ui/index.html,如图所示:

由此可说明,镜像可以下载并成功启动容器floodlight。

4 总结

Docker registry的安装和使用是实施并运用Dcoker的第一步,主要是因为公共的Docker Hub有时候比较慢,并且私有registry对企业内部而言,更加的安全可控,同时方便后期分发和维护标准的容器服务。除此之外,也可以通过Docker的RESTAPI(https://docs.docker.com/reference/api/registry_api/)或者第三方的编排框架管理registry。在本例子中镜像的存储在本地,当然也可以像openstack那样通过glance swift方案实现。

Docker安全性不成熟 但在可控范围内

导读:Docker自问世以来,已经闯出了响亮的名号,但近期的一份声明,向Docker的广大用户群体指出了其安全性还不够成熟.

Docker,SDN容器网络,

作者:管理员




现在致电4006-2991-90 OR 查看更多联系方式 →

Go To Top 回顶部