__author__ = 'zxp'
import docker
import sys
class DockerManager_Slave(object):
def __init__(self):
self.idict={}
self.rinfo={}
try:
self.c = docker.Client(base_url='unix://var/run/docker.sock',version='1.0.1',timeout=15)
except Exception,e:
print "Connection docker server error:"+str(e)
sys.exit()
def Create_Container(self,image,command=None,mem_limit=0,ports=None,name=None,cpu_shares=None):
"""
:param image (str): The image to run
:param command (str or list): The command to be run in the container
:param mem_limit (float or str): Memory limit (format: [number][optional unit], where unit = b, k, m, or g)
:param ports (list of ints): A list of port numbers
:param name (str): A name for the container
:param cpu_shares (int or float): CPU shares (relative weight)
Returns (dict): A dictionary with an image 'Id' key and a 'Warnings' key.
return container id
"""
try:
self.container = self.c.create_container(image=image, command=command,mem_limit=mem_limit,ports=ports,\
name=name,cpu_shares=cpu_shares)
except Exception,e:
print "Create Container error:"+str(e)
sys.exit()
return self.container['Id']
def Inspect_Container(self,containerid):
"""
:param containerid:The container to inspect
:return:Nearly the same output as docker inspect, just as a single dict
"""
try:
self.container_info=self.c.inspect_container(containerid)
except Exception,e:
print "Inspect Container"+containerid+"error:"+str(e)
sys.exit()
def Pull(self,repository,tag=None):
"""
:param repository (str): The repository to pull
:param tag (str): The tag to pull
:return (generator or str): The output
"""
try:
self.pull_detail=self.c.pull(repository,tag)
except Exception,e:
print "Pull images"+repository+":"+tag+"error:"+str(e)
sys.exit()
def Start(self,containerid):
try:
self.c.start(containerid)
except Exception,e:
print "Start Container"+containerid+"error:"+str(e)
def Stop(self,containerid,timeout=10):
"""
:param container (str): The container to stop
:param timeout (int): Timeout in seconds to wait for the container to stop before sending a SIGKILL
:return:
"""
try:
self.c.stop(containerid,timeout=timeout)
except Exception,e:
print "Stop"+containerid+"error:"+str(e)
sys.exit()
def Remove_Container(self,containerid):
"""
container (str): The container to remove
v (bool): Remove the volumes associated with the container
link (bool): Remove the specified link and not the underlying container
force (bool): Force the removal of a running container (uses SIGKILL)
"""
try:
self.c.remove_container(containerid)
except Exception,e:
print "Remove container"+containerid+"error:"+str(e)
sys.exit()

docker-api的更多相关文章

  1. Docker入门教程(七)Docker API

    Docker入门教程(七)Docker API [编者的话]DockerOne组织翻译了Flux7的Docker入门教程,本文是系列入门教程的第七篇,重点介绍了Docker Registry API和 ...

  2. 【漏洞挖掘】攻击对外开放的Docker API接口

    https://medium.com/@riccardo.ancarani94/attacking-docker-exposed-api-3e01ffc3c124 1)场景 攻击开放在互联网的Dock ...

  3. python调用docker API(CentOS6.5)

    一 环境背景 python-2.7.8 docker 版本 1.15 (*yum安装为1.14版本,需升级为1.15,详见后续步骤) 二 获取Docker容器指标[指标可行性分析见笔记:] CPU : ...

  4. docker API 配置与使用

    在网上看到一大堆乱乱七八招的博客,很多都不能用,我根据这些天踩的坑来总结一下吧 首先!怎么配置 docker API 两种方法 在/etc/sysconfig/docker文件里加一行OPTIONS= ...

  5. Docker for mac开启docker api调用

    docker-java 支持unix socket调用的 DefaultDockerClientConfig config = DefaultDockerClientConfig.createDefa ...

  6. Java 使用 UnixSocket 调用 Docker API

    在 Docker 官网查阅 API 调用方式 例如:查询正在运行的容器列表,HTTP 方式如下: $ curl --unix-socket /var/run/docker.sock http:/v1. ...

  7. python docker api

    开启Remote API docker默认是没有开启Remote API的,需要我们手动开启.编辑/lib/systemd/system/docker.service文件, 在文件里的ExecStar ...

  8. Docker Api 实测

    好久没写博客,工作中想着未来部门需要对docker进行维护相对麻烦,而且,网络上也缺少一些合适的项目,于是准备筹划自己动手.先找到了Docker 的API文档,地址是:https://docs.doc ...

  9. 使用docker api

    前提: 系统centos 7 docker version 1.10.3 使用systemd启动docker 访问方式: 修改/usr/lib/systemd/system/docker.servic ...

  10. Docker入门教程(八)Docker Remote API

    Docker入门教程(八)Docker Remote API [编者的话]DockerOne组织翻译了Flux7的Docker入门教程,本文是系列入门教程的第八篇,重点介绍了Docker Remote ...

随机推荐

  1. 【坚持】Selenium+Python学习之从读懂代码开始 DAY1

    学习Selenium+Python已经好几个月了,但越学发现不懂的东西越多. 感觉最大的问题还是在于基础不扎实,决定从头开始,每天坚持读代码,写代码. 相信量变一定能到质变!!! 2018/05/09 ...

  2. 关于js中一个对象当做参数传递是按值传递还是按引用传递的个人看法

    在<JavaScript高级程序设计>这本书中有这样一段话:有很多开发人员错误的认为:在局部作用域中修改的对象会在全局作用域中反映出来,就说明参数是按引用传递的.换句话说,尼古拉认为当一个 ...

  3. 经验之谈:10位顶级PHP大师的开发原则

    导读:在Web开发世界里,PHP是最流行的语言之一,从PHP里,你能够很容易的找到你所需的脚本,遗憾的是,很少人会去用“最佳做法”去写一个PHP程序.这里,我们向大家介绍PHP的10种最佳实践,当然, ...

  4. Oracle数据库拼音首字母模糊搜索

    1.建立函数 CREATE OR REPLACE FUNCTION F_PINYIN(P_NAME IN VARCHAR2) RETURN VARCHAR2 AS V_COMPARE ); V_RET ...

  5. 2017年软件工程第八次作业-每周PSP例行报告

    1.PSP表格 2.进度条 3.博文字数累积折线图 4.代码行数累积折线图 5.PSP饼图

  6. ZOJ 3946 Highway Project 贪心+最短路

    题目链接: http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=3946 题解: 用dijkstra跑单元最短路径,如果对于顶点v,存 ...

  7. HDU 5234 Happy birthday 01背包

    题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5234 bc:http://bestcoder.hdu.edu.cn/contests/con ...

  8. HDU 5265 pog loves szh II 二分

    题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5265 bc(中文):http://bestcoder.hdu.edu.cn/contests ...

  9. Spring管理过滤器:org.springframework.web.filter.DelegatingFilterProxy

    配置web.xml <filter>        <filter-name>springSecurityFilterChain</filter-name>     ...

  10. 【c】线性表

    数据对象集:线性表是N(>=0)个元素构成的有序序列,a1,a2,a3.....a(N-1),aN,a(N+1) 线性表上的基本操作有: ⑴ 线性表初始化:Init_List(L)初始条件:表L ...