@@ -76,7 +76,7 @@ func (s *composeService) down(ctx context.Context, projectName string, options a
76
76
77
77
err = InReverseDependencyOrder (ctx , project , func (c context.Context , service string ) error {
78
78
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 )
80
80
return err
81
81
}, WithRootNodesAndDown (options .Services ))
82
82
if err != nil {
@@ -85,7 +85,7 @@ func (s *composeService) down(ctx context.Context, projectName string, options a
85
85
86
86
orphans := containers .filter (isOrphaned (project ))
87
87
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 )
89
89
if err != nil {
90
90
return err
91
91
}
@@ -303,32 +303,37 @@ func (s *composeService) stopContainers(ctx context.Context, w progress.Writer,
303
303
return eg .Wait ()
304
304
}
305
305
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 {
307
307
eg , _ := errgroup .WithContext (ctx )
308
308
for _ , container := range containers {
309
309
container := container
310
310
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 )
327
312
})
328
313
}
329
314
return eg .Wait ()
330
315
}
331
316
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
+
332
337
func (s * composeService ) getProjectWithResources (ctx context.Context , containers Containers , projectName string ) (* types.Project , error ) {
333
338
containers = containers .filter (isNotOneOff )
334
339
project , err := s .projectFromName (containers , projectName )
0 commit comments