__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. 高可用Kubernetes集群-5. 部署flannel网络

    七.部署flannel网络 kubernetes支持基于vxlan方式的flannel与weave网络,基于BGP路由的Calico网络,本节采用flannel网络. Flannel网络采用etcd等 ...

  2. js页面跳转,url带url参数解决方案

    今天,在做一个项目的时候,向后端发送了一个Ajax请求,后端返回了一个字符串,告诉我未登录.那么我需要跳转到登录页面,同时告诉登录页面,登录成功后,需要跳回的url.也就是标题所说,url中的一个参数 ...

  3. React Native 【学习总结】-【常用命令】

    前言 刚接触RN,相信很多人无从下手,不知道下一步要干什么,能干什么,本次学习围绕这个问题,将RN的常用命令总结一下,帮助你快速上手 架构理解 光知道命令的作用,远远不够,如果知道命令背后的意义,才能 ...

  4. Walking Between Houses(贪心+思维)

    Walking Between Houses There are nn houses in a row. They are numbered from 11 to nn in order from l ...

  5. Android开发第二阶段(3)

    今天:对闹钟代码的按钮事件进行了添加和修改.对监听器的相关应用也有了进一步的了解和深入. 明天:对主界面的代码的优化比如对按钮位置的调节等细节处理.

  6. paoding rose controller包及文件名命名规则

    1.包命名规则:xxx.xxx.controllers(否则扫描不到)

  7. CentOS6.5 重启网络报错:Bringing up interface eth0: Error: Connection activation failed: Device not managed by NetworkManager or unavailable

    CentOS6.5 重启网络报错: Bringing up interface eth0: Error: Connection activation failed: Device not manage ...

  8. linux 下svn忽略文件

    假设想忽略文件temp 1. cd到temp所在的目录下: 2. svn propedit svn:ignore . 注意:请别漏掉最后的点(.表示当前目录),如果报错请看下面 3. 打开的文件就是忽 ...

  9. NLP 入门

    作者:微软亚洲研究院链接:https://www.zhihu.com/question/19895141/answer/149475410来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业 ...

  10. Delphi通过ADO链接数据库及对数据库的增加,删除,修改,读取操作实例教程4

    ADO是一种程序对象,用于表示用户数据库中的数据结构和所包含的数据.ADO(ActiveXDataObjects,ActiveX数据对象)是Microsoft提出的应用程序接口(API)用以实现访问关 ...