def stop(self, containers): if not containers: return args = [docker_bin, 'stop'] args.extend(containers) p = popen(args, stdout=subprocess.PIPE) p.wait()
def rmi(self, images): if not images: return args = [docker_bin, 'rmi'] args.extend(images) p = popen(args, stdout=subprocess.PIPE) p.wait()
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')
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
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]
def shell(self, container): if not container: return args = [docker_bin, 'exec', '-it', container, '/bin/bash'] p = popen(args) p.wait()
def machine_ssh(self, args): args = ['/usr/local/bin/docker-machine', 'ssh', 'foo'] args.extend(args) p = popen(args) p.wait()
def exec(self, container, *vargs): args = [docker_bin, 'exec', '-it', container] args.extend(vargs) p = popen(args) p.wait()
def local_cmd(args): p = popen(args) p.wait()