mirror of https://github.com/docker/compose.git
Implement kill and rm
This commit is contained in:
parent
a4710fa9e1
commit
81093627fe
|
@ -71,6 +71,8 @@ class TopLevelCommand(Command):
|
|||
run Run a one-off command
|
||||
start Start services
|
||||
stop Stop services
|
||||
kill Kill containers
|
||||
rm Remove stopped containers
|
||||
|
||||
"""
|
||||
def docopt_options(self):
|
||||
|
@ -186,6 +188,22 @@ class TopLevelCommand(Command):
|
|||
"""
|
||||
self.project.stop()
|
||||
|
||||
def kill(self, options):
|
||||
"""
|
||||
Kill all containers
|
||||
|
||||
Usage: kill
|
||||
"""
|
||||
self.project.kill()
|
||||
|
||||
def rm(self, options):
|
||||
"""
|
||||
Remove all stopped containers
|
||||
|
||||
Usage: rm
|
||||
"""
|
||||
self.project.remove_stopped()
|
||||
|
||||
def logs(self, options):
|
||||
"""
|
||||
View output from containers
|
||||
|
|
|
@ -74,6 +74,14 @@ class Project(object):
|
|||
for service in self.services:
|
||||
service.stop(**options)
|
||||
|
||||
def kill(self, **options):
|
||||
for service in self.services:
|
||||
service.kill(**options)
|
||||
|
||||
def remove_stopped(self, **options):
|
||||
for service in self.services:
|
||||
service.remove_stopped(**options)
|
||||
|
||||
def containers(self, *args, **kwargs):
|
||||
l = []
|
||||
for service in self.services:
|
||||
|
|
|
@ -47,6 +47,15 @@ class Service(object):
|
|||
for c in self.containers():
|
||||
c.stop(**options)
|
||||
|
||||
def kill(self, **options):
|
||||
for c in self.containers():
|
||||
c.kill(**options)
|
||||
|
||||
def remove_stopped(self, **options):
|
||||
for c in self.containers(stopped=True):
|
||||
if not c.is_running:
|
||||
c.remove(**options)
|
||||
|
||||
def create_container(self, one_off=False, **override_options):
|
||||
"""
|
||||
Create a container for this service. If the image doesn't exist, attempt to pull
|
||||
|
|
|
@ -73,6 +73,22 @@ class ServiceTest(DockerClientTestCase):
|
|||
self.assertEqual(len(service.containers()), 0)
|
||||
self.assertEqual(len(service.containers(stopped=True)), 1)
|
||||
|
||||
def test_kill_remove(self):
|
||||
service = self.create_service('scalingtest')
|
||||
|
||||
service.start_container()
|
||||
self.assertEqual(len(service.containers()), 1)
|
||||
|
||||
service.remove_stopped()
|
||||
self.assertEqual(len(service.containers()), 1)
|
||||
|
||||
service.kill()
|
||||
self.assertEqual(len(service.containers()), 0)
|
||||
self.assertEqual(len(service.containers(stopped=True)), 1)
|
||||
|
||||
service.remove_stopped()
|
||||
self.assertEqual(len(service.containers(stopped=True)), 0)
|
||||
|
||||
def test_create_container_with_one_off(self):
|
||||
db = self.create_service('db')
|
||||
container = db.create_container(one_off=True)
|
||||
|
|
Loading…
Reference in New Issue