def list_containers(label: Optional[str] = None): """ Lists Docker Containers """ with sudo: if label is None: docker.ps(_fg=True) else: docker.ps(filter='label={}'.format(label), _fg=True)
def __build_base_image(self, config): # This does not seem to be the right way to get the container tag? self.container_tag = config.get_container_tag() all_images = docker.images(a=True) import pdb; pdb.set_trace() if self.container_tag in all_images: return print ("Container not found or changes in watched files. Rebuilding base container (%s)..." % self.container_tag) base_name = 'nose-docker-base-%s' % self.container_tag all_containers = docker.ps(a=True) if base_name in all_containers: docker.rm('-f', base_name) docker.run( '--name=%s' % base_name, '-v', '%s:/app' % abspath(os.curdir), config.base_image, '/bin/bash', c="cd /app && %s" % ( " && ".join(config.build_commands) ), _out=sys.stdout ) docker.commit('nose-docker-base-%s' % self.container_tag, 'nose-docker:%s' % self.container_tag)
def setUp(self): """ Clean up host containers before every test. """ containers = docker.ps("-qa").split() for container in containers: DockerHost.delete_container(container)
def __build_base_image(self, config): # This does not seem to be the right way to get the container tag? self.container_tag = config.get_container_tag() all_images = docker.images(a=True) import pdb pdb.set_trace() if self.container_tag in all_images: return print( "Container not found or changes in watched files. Rebuilding base container (%s)..." % self.container_tag) base_name = 'nose-docker-base-%s' % self.container_tag all_containers = docker.ps(a=True) if base_name in all_containers: docker.rm('-f', base_name) docker.run('--name=%s' % base_name, '-v', '%s:/app' % abspath(os.curdir), config.base_image, '/bin/bash', c="cd /app && %s" % (" && ".join(config.build_commands)), _out=sys.stdout) docker.commit('nose-docker-base-%s' % self.container_tag, 'nose-docker:%s' % self.container_tag)
def tearDown(self): """ Clean up host containers after every test. """ containers = docker.ps("-qa").split() for container in containers: DockerHost.delete_container(container)
def containers(ctx, force, all): """clean docker containers which not running""" all_containers = docker.ps('-a', '-q').stdout.split() if all: removed_containers = all_containers else: running_containers = docker.ps('-q').stdout.split() removed_containers = set(all_containers) ^ set(running_containers) for cid in removed_containers: ctx.log('docker removing container %s' % cid) if force: print(docker.rm('-f', cid)) else: print(docker.rm(cid)) ctx.log('list all containers') print(docker.ps('-a'))
def tearDown(self): """ Clean up host containers after every test. """ if do_teardown(): containers = docker.ps("-qa").split() for container in containers: delete_container(container)
def setUp(self): """ Clean up host containers before every test. """ containers = docker.ps("-qa").split() for container in containers: delete_container(container) self.ip = get_ip() self.start_etcd()