Merge pull request #6342 from collin5/b5547

--remove-orphans is ignored when using up --no-start
This commit is contained in:
Ian Campbell 2019-05-20 15:45:24 +01:00 committed by GitHub
commit a89128118b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 2 deletions

View File

@ -690,7 +690,7 @@ class Project(object):
def find_orphan_containers(self, remove_orphans): def find_orphan_containers(self, remove_orphans):
def _find(): def _find():
containers = self._labeled_containers() containers = set(self._labeled_containers() + self._labeled_containers(stopped=True))
for ctnr in containers: for ctnr in containers:
service_name = ctnr.labels.get(LABEL_SERVICE) service_name = ctnr.labels.get(LABEL_SERVICE)
if service_name not in self.service_names: if service_name not in self.service_names:
@ -701,7 +701,10 @@ class Project(object):
if remove_orphans: if remove_orphans:
for ctnr in orphans: for ctnr in orphans:
log.info('Removing orphan container "{0}"'.format(ctnr.name)) log.info('Removing orphan container "{0}"'.format(ctnr.name))
ctnr.kill() try:
ctnr.kill()
except APIError:
pass
ctnr.remove(force=True) ctnr.remove(force=True)
else: else:
log.warning( log.warning(

View File

@ -11,6 +11,7 @@ import subprocess
import time import time
from collections import Counter from collections import Counter
from collections import namedtuple from collections import namedtuple
from functools import reduce
from operator import attrgetter from operator import attrgetter
import pytest import pytest
@ -1157,6 +1158,22 @@ class CLITestCase(DockerClientTestCase):
] ]
assert len(remote_volumes) > 0 assert len(remote_volumes) > 0
@v2_only()
def test_up_no_start_remove_orphans(self):
self.base_dir = 'tests/fixtures/v2-simple'
self.dispatch(['up', '--no-start'], None)
services = self.project.get_services()
stopped = reduce((lambda prev, next: prev.containers(
stopped=True) + next.containers(stopped=True)), services)
assert len(stopped) == 2
self.dispatch(['-f', 'one-container.yml', 'up', '--no-start', '--remove-orphans'], None)
stopped2 = reduce((lambda prev, next: prev.containers(
stopped=True) + next.containers(stopped=True)), services)
assert len(stopped2) == 1
@v2_only() @v2_only()
def test_up_no_ansi(self): def test_up_no_ansi(self):
self.base_dir = 'tests/fixtures/v2-simple' self.base_dir = 'tests/fixtures/v2-simple'

View File

@ -0,0 +1,5 @@
version: "2"
services:
simple:
image: busybox:latest
command: top