@@ -76,7 +76,7 @@ func (s *composeService) down(ctx context.Context, projectName string, options a
7676
7777 err = InReverseDependencyOrder (ctx , project , func (c context.Context , service string ) error {
7878 serviceContainers := containers .filter (isService (service ))
79- err := s .removeContainers (ctx , w , serviceContainers , options .Timeout , options .Volumes )
79+ err := s .removeContainers (ctx , serviceContainers , options .Timeout , options .Volumes )
8080 return err
8181 }, WithRootNodesAndDown (options .Services ))
8282 if err != nil {
@@ -85,7 +85,7 @@ func (s *composeService) down(ctx context.Context, projectName string, options a
8585
8686 orphans := containers .filter (isOrphaned (project ))
8787 if options .RemoveOrphans && len (orphans ) > 0 {
88- err := s .removeContainers (ctx , w , orphans , options .Timeout , false )
88+ err := s .removeContainers (ctx , orphans , options .Timeout , false )
8989 if err != nil {
9090 return err
9191 }
@@ -303,32 +303,37 @@ func (s *composeService) stopContainers(ctx context.Context, w progress.Writer,
303303 return eg .Wait ()
304304}
305305
306- func (s * composeService ) removeContainers (ctx context.Context , w progress. Writer , containers []moby.Container , timeout * time.Duration , volumes bool ) error {
306+ func (s * composeService ) removeContainers (ctx context.Context , containers []moby.Container , timeout * time.Duration , volumes bool ) error {
307307 eg , _ := errgroup .WithContext (ctx )
308308 for _ , container := range containers {
309309 container := container
310310 eg .Go (func () error {
311- eventName := getContainerProgressName (container )
312- err := s .stopContainer (ctx , w , container , timeout )
313- if err != nil {
314- return err
315- }
316- w .Event (progress .RemovingEvent (eventName ))
317- err = s .apiClient ().ContainerRemove (ctx , container .ID , containerType.RemoveOptions {
318- Force : true ,
319- RemoveVolumes : volumes ,
320- })
321- if err != nil && ! errdefs .IsNotFound (err ) && ! errdefs .IsConflict (err ) {
322- w .Event (progress .ErrorMessageEvent (eventName , "Error while Removing" ))
323- return err
324- }
325- w .Event (progress .RemovedEvent (eventName ))
326- return nil
311+ return s .stopAndRemoveContainer (ctx , container , timeout , volumes )
327312 })
328313 }
329314 return eg .Wait ()
330315}
331316
317+ func (s * composeService ) stopAndRemoveContainer (ctx context.Context , container moby.Container , timeout * time.Duration , volumes bool ) error {
318+ w := progress .ContextWriter (ctx )
319+ eventName := getContainerProgressName (container )
320+ err := s .stopContainer (ctx , w , container , timeout )
321+ if err != nil {
322+ return err
323+ }
324+ w .Event (progress .RemovingEvent (eventName ))
325+ err = s .apiClient ().ContainerRemove (ctx , container .ID , containerType.RemoveOptions {
326+ Force : true ,
327+ RemoveVolumes : volumes ,
328+ })
329+ if err != nil && ! errdefs .IsNotFound (err ) && ! errdefs .IsConflict (err ) {
330+ w .Event (progress .ErrorMessageEvent (eventName , "Error while Removing" ))
331+ return err
332+ }
333+ w .Event (progress .RemovedEvent (eventName ))
334+ return nil
335+ }
336+
332337func (s * composeService ) getProjectWithResources (ctx context.Context , containers Containers , projectName string ) (* types.Project , error ) {
333338 containers = containers .filter (isNotOneOff )
334339 project , err := s .projectFromName (containers , projectName )
0 commit comments