__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. JAVA学习笔记--接口

    一.抽象类和抽象方法 在谈论接口之前,我们先了解一下抽象类和抽象方法.我们知道,在继承结构中,越往下继承,类会变得越来越明确和具体,而往上回溯,越往上,类会变得越抽象和通用.我们有时候可能会需要这样一 ...

  2. 微软职位内部推荐-Senior Software Engineer II-Sharepoint

    微软近期Open的职位: SharePoint is a multi-billion dollar enterprise business that has grown from an on-prem ...

  3. spark-local-运行异常-Could not locate executable null\bin\winutils.exe in the Hadoop binaries

    windows下-local模式-运行spark: 1.下载winutils的windows版本 GitHub上,有人提供了winutils的windows的版本,项目地址是:https://gith ...

  4. Vue工作原理小结

    本文能帮你做什么?1.了解vue的双向数据绑定原理以及核心代码模块2.缓解好奇心的同时了解如何实现双向绑定为了便于说明原理与实现,本文相关代码主要摘自vue源码, 并进行了简化改造,相对较简陋,并未考 ...

  5. PIGCMS 关闭聊天机器人(小黄鸡)

    无脑操作举例 1.找到 WeixinAction.class.php 文件,路径: 你的版本\PigCms\Lib\Action\Home 2.查询 function chat ,在 chat() 函 ...

  6. 第三次c++作业

    https://github.com/egoistor/3Elevators-scheduling 老实说,因为这周时间紧张,(高数的期中考和一些奇奇怪怪的时期), 所以代码大体是有,但是很多细节处理 ...

  7. Java中的网络编程-2

    Socket编程:(一般的网络编程) <1> 两个 JAVA 应用程序可通过一个双向的网络通信连接, 实现数据交换, 这个双向链路的一段称为一个 Socket. <2> Soc ...

  8. 跨域写cookie

    假设a站想往b站写cookie,那么目前有两种方案,参考如下: 第一种(使用jsonp): a站js代码如下: $.ajax({ url: 'http://www.b.com/jsonp.jsp?do ...

  9. 浅析GCC下C++多重继承 & 虚拟继承的对象内存布局

    继承是C++作为OOD程序设计语言的三大特征(封装,继承,多态)之一,单一非多态继承是比较好理解的,本文主要讲解GCC环境下的多重继承和虚拟继承的对象内存布局. 一.多重继承 先看几个类的定义: 01 ...

  10. freemarker中空值 null的处理 ?exists ?if_exists ?default(“”)

    exists:由空值测试运算符的引入,它被废弃了. exp1?exists 和 exp1??是一样的, ( exp1)?exists 和(exp1)??也是一样的. if_exists:由默认值运算符 ...