码迷,mamicode.com
首页 > 其他好文 > 详细

docker-py的配置与使用

时间:2015-07-24 22:15:39      阅读:353      评论:0      收藏:0      [点我收藏+]

标签:

测试环境

75机:Red Hat Enterprise Linux Server 7.0,无外网访问权限

73机:Red Hat Enterprise Linux Server 7.0,无外网访问权限,已安装Docker Server

183机:OS X Yosemite 10.10.4,完全外网访问,用于下载安装包

配置过程

1. 如果开发环境可联网,则直接通过如下命令进行安装即可:

sudo pip install docker-py

如果没有安装pip命令,可通过如下命令进行安装:

sudo easy_install pip

2. 如果不能连外网,则需要从github的docker-py页面中下载zip包docker-py-master.zip进行离线安装。下载完之后,将zip包从183机scp到75机中:

scp docker-py-master.zip scs@10.11.150.75:/opt/scs/openxxs/

在75机上解压:

unzip docker-py-master.zip

查看setup.py文件,发现有三个依赖包需要安装,且有版本要求:

requirements = [
    requests >= 2.5.2,
    six >= 1.3.0,
    websocket-client >= 0.32.0,
]

可从如下网站下载 requests、six和websocket-client 三个安装包(如果不知道具体url,运行sudo python setup.py install时会有提示):

requests: https://pypi.python.org/simple/requests/
six: https://pypi.python.org/simple/six/
websocket-client: https://pypi.python.org/simple/websocket-client/

下载完成后scp到75机上再使用 tar -zxvf 解压,依照如下顺序安装:

cd requests-2.7.0
sudo python setup.py install
cd ../six-1.9.0
sudo python setup.py install
cd ../websocket_client-0.32.0
sudo python setup.py install
cd ../docker-py-master
sudo python setup.py install

3. 在73机上用同样方式安装docker-py

4. 以Unix Socket方式在73机上启动docker server:

[@tc_150_73 ~]$ sudo docker -d &
[1] 1255
[@tc_150_73 ~]$ INFO[0000] Listening for HTTP on unix (/var/run/docker.sock) 
INFO[0000] [graphdriver] using prior storage driver "devicemapper" 
WARN[0000] Running modprobe bridge nf_nat failed with message: , error: exit status 1 
INFO[0000] Loading containers: start.                   
..
INFO[0000] Loading containers: done.                    
INFO[0000] Daemon has completed initialization          
INFO[0000] Docker daemon                                 commit=0baf609 execdriver=native-0.2 graphdriver=devicemapper version=1.7.0

在73机上开启若干个docker容器后进行测试,测试如下:

[@tc_150_73 ~]$ python
Python 2.7.5 (default, Apr  9 2015, 11:03:32) 
[GCC 4.8.3 20140911 (Red Hat 4.8.3-9)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from docker import Client
>>> clt = Client(base_url=unix://var/run/docker.sock)
>>> clt.containers()
[{uStatus: uUp About a minute, uCreated: 1437743168, uImage: ucentos:7, uLabels: {}, uPorts: [], uCommand: u/bin/bash, uNames: [u/suspicious_galileo], uId: ua81dbf9200fbf6a4180e8b8e80f4fe30b3f8be612ea0e58ac04fb65080429043}]
>>> 

可以看到正常显示了正在运行中的容器,Unix Socket方式测试成功。

5. 关闭73机上刚才开启的docker server(使用service docker stop 和 systemctl docker stop方式停止无效):

sudo killall docker

6. 以TCP方式在73机上启动docker server:

[@tc_150_73 ~]$ sudo docker -H 0.0.0.0:2375 -d &
[1] 1625
[@tc_150_73 ~]$ WARN[0000] /!\ DONT BIND ON ANY IP ADDRESS WITHOUT setting -tlsverify IF YOU DONT KNOW WHAT YOURE DOING /!\ 
INFO[0000] Listening for HTTP on tcp (0.0.0.0:2375)     
INFO[0000] [graphdriver] using prior storage driver "devicemapper" 
WARN[0000] Running modprobe bridge nf_nat failed with message: , error: exit status 1 
INFO[0000] Loading containers: start.                   
....
INFO[0000] Loading containers: done.                    
INFO[0000] Daemon has completed initialization          
INFO[0000] Docker daemon                                 commit=0baf609 execdriver=native-0.2 graphdriver=devicemapper version=1.7.0

在75机上进行测试,测试结果如下:

[@tc_150_75 ~]$ python
Python 2.7.5 (default, Apr  9 2015, 11:03:32) 
[GCC 4.8.3 20140911 (Red Hat 4.8.3-9)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from docker import Client
>>> clt = Client(base_url=tcp://10.11.150.73:30001)
>>> clt.containers()
[]

TCP方式测试成功(此时显示的是73机上的正在运行的容器状态,没有,所以为空)。

相关安装包百度云备份

http://pan.baidu.com/s/1sjmi8OH

docker-py的配置与使用

标签:

原文地址:http://www.cnblogs.com/openxxs/p/4674720.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!