mirror of
https://github.com/docker/compose.git
synced 2025-07-21 20:54:32 +02:00
Merge pull request #139 from orchardup/fix-delete-volume
Fix delete volume
This commit is contained in:
commit
71533791dd
@ -170,19 +170,23 @@ class TopLevelCommand(Command):
|
|||||||
"""
|
"""
|
||||||
Remove stopped service containers.
|
Remove stopped service containers.
|
||||||
|
|
||||||
Usage: rm [SERVICE...]
|
Usage: rm [options] [SERVICE...]
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
-v Remove volumes associated with containers
|
--force Don't ask to confirm removal
|
||||||
|
-v Remove volumes associated with containers
|
||||||
"""
|
"""
|
||||||
all_containers = self.project.containers(service_names=options['SERVICE'], stopped=True)
|
all_containers = self.project.containers(service_names=options['SERVICE'], stopped=True)
|
||||||
stopped_containers = [c for c in all_containers if not c.is_running]
|
stopped_containers = [c for c in all_containers if not c.is_running]
|
||||||
|
|
||||||
if len(stopped_containers) > 0:
|
if len(stopped_containers) > 0:
|
||||||
print("Going to remove", list_containers(stopped_containers))
|
print("Going to remove", list_containers(stopped_containers))
|
||||||
if yesno("Are you sure? [yN] ", default=False):
|
if options.get('--force') \
|
||||||
self.project.remove_stopped(service_names=options['SERVICE'],
|
or yesno("Are you sure? [yN] ", default=False):
|
||||||
remove_volumes=options['-v'])
|
self.project.remove_stopped(
|
||||||
|
service_names=options['SERVICE'],
|
||||||
|
v=options.get('-v', False)
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
print("No stopped containers")
|
print("No stopped containers")
|
||||||
|
|
||||||
|
@ -112,8 +112,7 @@ class Container(object):
|
|||||||
return self.client.kill(self.id)
|
return self.client.kill(self.id)
|
||||||
|
|
||||||
def remove(self, **options):
|
def remove(self, **options):
|
||||||
v = options.get('remove_volumes', False)
|
return self.client.remove_container(self.id, **options)
|
||||||
return self.client.remove_container(self.id, v=v)
|
|
||||||
|
|
||||||
def inspect_if_not_inspected(self):
|
def inspect_if_not_inspected(self):
|
||||||
if not self.has_been_inspected:
|
if not self.has_been_inspected:
|
||||||
|
@ -32,7 +32,7 @@ class CLITestCase(DockerClientTestCase):
|
|||||||
self.assertIn('fig_simple_1', mock_stdout.getvalue())
|
self.assertIn('fig_simple_1', mock_stdout.getvalue())
|
||||||
|
|
||||||
@patch('sys.stdout', new_callable=StringIO)
|
@patch('sys.stdout', new_callable=StringIO)
|
||||||
def test_default_figfile(self, mock_stdout):
|
def test_ps_default_figfile(self, mock_stdout):
|
||||||
self.command.base_dir = 'tests/fixtures/multiple-figfiles'
|
self.command.base_dir = 'tests/fixtures/multiple-figfiles'
|
||||||
self.command.dispatch(['up', '-d'], None)
|
self.command.dispatch(['up', '-d'], None)
|
||||||
self.command.dispatch(['ps'], None)
|
self.command.dispatch(['ps'], None)
|
||||||
@ -43,7 +43,7 @@ class CLITestCase(DockerClientTestCase):
|
|||||||
self.assertNotIn('fig_yetanother_1', output)
|
self.assertNotIn('fig_yetanother_1', output)
|
||||||
|
|
||||||
@patch('sys.stdout', new_callable=StringIO)
|
@patch('sys.stdout', new_callable=StringIO)
|
||||||
def test_alternate_figfile(self, mock_stdout):
|
def test_ps_alternate_figfile(self, mock_stdout):
|
||||||
self.command.base_dir = 'tests/fixtures/multiple-figfiles'
|
self.command.base_dir = 'tests/fixtures/multiple-figfiles'
|
||||||
self.command.dispatch(['-f', 'fig2.yml', 'up', '-d'], None)
|
self.command.dispatch(['-f', 'fig2.yml', 'up', '-d'], None)
|
||||||
self.command.dispatch(['-f', 'fig2.yml', 'ps'], None)
|
self.command.dispatch(['-f', 'fig2.yml', 'ps'], None)
|
||||||
@ -53,6 +53,14 @@ class CLITestCase(DockerClientTestCase):
|
|||||||
self.assertNotIn('fig_another_1', output)
|
self.assertNotIn('fig_another_1', output)
|
||||||
self.assertIn('fig_yetanother_1', output)
|
self.assertIn('fig_yetanother_1', output)
|
||||||
|
|
||||||
|
def test_rm(self):
|
||||||
|
service = self.command.project.get_service('simple')
|
||||||
|
service.create_container()
|
||||||
|
service.kill()
|
||||||
|
self.assertEqual(len(service.containers(stopped=True)), 1)
|
||||||
|
self.command.dispatch(['rm', '--force'], None)
|
||||||
|
self.assertEqual(len(service.containers(stopped=True)), 0)
|
||||||
|
|
||||||
def test_scale(self):
|
def test_scale(self):
|
||||||
project = self.command.project
|
project = self.command.project
|
||||||
|
|
||||||
@ -74,4 +82,3 @@ class CLITestCase(DockerClientTestCase):
|
|||||||
self.command.scale({'SERVICE=NUM': ['simple=0', 'another=0']})
|
self.command.scale({'SERVICE=NUM': ['simple=0', 'another=0']})
|
||||||
self.assertEqual(len(project.get_service('simple').containers()), 0)
|
self.assertEqual(len(project.get_service('simple').containers()), 0)
|
||||||
self.assertEqual(len(project.get_service('another').containers()), 0)
|
self.assertEqual(len(project.get_service('another').containers()), 0)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user