#NEWLINE# def find_orphan_containers( self , remove_orphans ) : #NEWLINE# #INDENT# def _find( ) : #NEWLINE# #INDENT# containers = self . _labeled_containers ( ) #NEWLINE# for ctnr in containers : #NEWLINE# #INDENT# service_name = ctnr . labels . get ( LABEL_SERVICE ) #NEWLINE# if ( service_name not in self . service_names ) : #NEWLINE# #INDENT# ( yield ctnr ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# orphans = list ( _find ( ) ) #NEWLINE# if ( not orphans ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# if remove_orphans : #NEWLINE# #INDENT# for ctnr in remove_orphans : #NEWLINE# #INDENT# log . info ( 'Removing orphan container "{0}"' . format ( ctnr . name ) ) #NEWLINE# ctnr . kill ( ) #NEWLINE# ctnr . remove ( force = True ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# log . warning ( 'Found orphan containers ({0}) for this project. If you removed or renamed this service in your compose file, you can run this command with the --remove-orphans flag to clean it up.' . format ( ', ' . join ( [ '{}' . format ( ctnr . name ) for ctnr in orphans ] ) ) )