示例#1
0
 def stop(self, containers):
     if not containers:
         return
     args = [docker_bin, 'stop']
     args.extend(containers)
     p = popen(args, stdout=subprocess.PIPE)
     p.wait()
示例#2
0
 def rmi(self, images):
     if not images:
         return
     args = [docker_bin, 'rmi']
     args.extend(images)
     p = popen(args, stdout=subprocess.PIPE)
     p.wait()
示例#3
0
def host_ip():
    machine = os.environ['DOCKER_MACHINE_NAME']

    args = ['docker-machine', 'ip', machine]
    p = popen(args, stdout=subprocess.PIPE)
    for line in p.stdout:
        pass
    p.wait()

    return line.strip().decode('utf-8')
示例#4
0
    def build(self, *vargs):
        args = [docker_bin, 'build']
        args.extend(vargs)
        p = popen(args, stdout=subprocess.PIPE)
        for line in p.stdout:
            line = line.decode('utf-8')
            sys.stdout.write(line)
        p.wait()

        if p.returncode == 0:
            image = line.split()[2]
            return image
示例#5
0
    def inspect(self, container, values):
        if not container:
            return
        format = '{{.%s}}' % '}}:{{.'.join(values)

        args = [docker_bin, 'inspect', '--format', format, container]
        p = popen(args, stdout=subprocess.PIPE)
        table = []
        for line in p.stdout:
            line = line.decode('utf-8').rstrip()
            fields = line.split(':')
            table.append({h: f for h, f in zip(values, fields)})

        p.wait()
        return table[0]
示例#6
0
 def shell(self, container):
     if not container:
         return
     args = [docker_bin, 'exec', '-it', container, '/bin/bash']
     p = popen(args)
     p.wait()
示例#7
0
 def machine_ssh(self, args):
     args = ['/usr/local/bin/docker-machine', 'ssh', 'foo']
     args.extend(args)
     p = popen(args)
     p.wait()
示例#8
0
 def exec(self, container, *vargs):
     args = [docker_bin, 'exec', '-it', container]
     args.extend(vargs)
     p = popen(args)
     p.wait()
示例#9
0
def local_cmd(args):
    p = popen(args)
    p.wait()