Merge pull request #4040 from rawkode/feature/allow-running-containers-to-be-deleted

Allowing running containers to be rm'd by stop flag
This commit is contained in:
Joffrey F 2017-03-06 18:34:19 -08:00 committed by GitHub
commit 01fa147183
2 changed files with 15 additions and 0 deletions

View File

@ -680,6 +680,7 @@ class TopLevelCommand(object):
Options:
-f, --force Don't ask to confirm removal
-s, --stop Stop the containers, if required, before removing
-v Remove any anonymous volumes attached to containers
-a, --all Deprecated - no effect.
"""
@ -690,6 +691,15 @@ class TopLevelCommand(object):
)
one_off = OneOffFilter.include
if options.get('--stop'):
running_containers = self.project.containers(
service_names=options['SERVICE'], stopped=False, one_off=one_off
)
self.project.stop(
service_names=running_containers,
one_off=one_off
)
all_containers = self.project.containers(
service_names=options['SERVICE'], stopped=True, one_off=one_off
)

View File

@ -1547,6 +1547,11 @@ class CLITestCase(DockerClientTestCase):
self.assertEqual(len(service.containers(stopped=True)), 1)
self.dispatch(['rm', '-f'], None)
self.assertEqual(len(service.containers(stopped=True)), 0)
service = self.project.get_service('simple')
service.create_container()
self.dispatch(['rm', '-fs'], None)
simple = self.project.get_service('simple')
self.assertEqual(len(simple.containers()), 0)
def test_rm_all(self):
service = self.project.get_service('simple')