@@ -66,7 +66,7 @@ func (s *composeService) down(ctx context.Context, projectName string, options c
66
66
67
67
err = InReverseDependencyOrder (ctx , options .Project , func (c context.Context , service types.ServiceConfig ) error {
68
68
serviceContainers := containers .filter (isService (service .Name ))
69
- err := s .removeContainers (ctx , w , serviceContainers , options .Timeout )
69
+ err := s .removeContainers (ctx , w , serviceContainers , options .Timeout , options . Volumes )
70
70
return err
71
71
})
72
72
if err != nil {
@@ -75,7 +75,7 @@ func (s *composeService) down(ctx context.Context, projectName string, options c
75
75
76
76
orphans := containers .filter (isNotService (options .Project .ServiceNames ()... ))
77
77
if options .RemoveOrphans && len (orphans ) > 0 {
78
- err := s .removeContainers (ctx , w , orphans , options .Timeout )
78
+ err := s .removeContainers (ctx , w , orphans , options .Timeout , false )
79
79
if err != nil {
80
80
return err
81
81
}
@@ -215,7 +215,7 @@ func (s *composeService) stopContainers(ctx context.Context, w progress.Writer,
215
215
return eg .Wait ()
216
216
}
217
217
218
- func (s * composeService ) removeContainers (ctx context.Context , w progress.Writer , containers []moby.Container , timeout * time.Duration ) error {
218
+ func (s * composeService ) removeContainers (ctx context.Context , w progress.Writer , containers []moby.Container , timeout * time.Duration , volumes bool ) error {
219
219
eg , _ := errgroup .WithContext (ctx )
220
220
for _ , container := range containers {
221
221
toDelete := container
@@ -228,7 +228,10 @@ func (s *composeService) removeContainers(ctx context.Context, w progress.Writer
228
228
return err
229
229
}
230
230
w .Event (progress .RemovingEvent (eventName ))
231
- err = s .apiClient .ContainerRemove (ctx , toDelete .ID , moby.ContainerRemoveOptions {Force : true })
231
+ err = s .apiClient .ContainerRemove (ctx , toDelete .ID , moby.ContainerRemoveOptions {
232
+ Force : true ,
233
+ RemoveVolumes : volumes ,
234
+ })
232
235
if err != nil {
233
236
w .Event (progress .ErrorMessageEvent (eventName , "Error while Removing" ))
234
237
return err
0 commit comments