Skip to content

Commit 2b4da1e

Browse files
committed
chore: remove anonymous volumes created by service containers when removing them
1 parent 4c77fe2 commit 2b4da1e

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

pkg/client/deploy/operation.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,10 @@ func (o *RemoveContainerOperation) Execute(ctx context.Context, cli Client) erro
9595
if err := cli.StopContainer(ctx, o.ServiceID, o.ContainerID, container.StopOptions{}); err != nil {
9696
return fmt.Errorf("stop container: %w", err)
9797
}
98-
if err := cli.RemoveContainer(ctx, o.ServiceID, o.ContainerID, container.RemoveOptions{}); err != nil {
98+
if err := cli.RemoveContainer(ctx, o.ServiceID, o.ContainerID, container.RemoveOptions{
99+
// Remove anonymous volumes created by the container.
100+
RemoveVolumes: true,
101+
}); err != nil {
99102
return fmt.Errorf("remove container: %w", err)
100103
}
101104

pkg/client/service.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,10 @@ func (cli *Client) RemoveService(ctx context.Context, id string) error {
251251
return
252252
}
253253

254-
err = cli.RemoveContainer(ctx, svc.ID, mc.Container.ID, container.RemoveOptions{})
254+
err = cli.RemoveContainer(ctx, svc.ID, mc.Container.ID, container.RemoveOptions{
255+
// Remove anonymous volumes created by the container.
256+
RemoveVolumes: true,
257+
})
255258
if err != nil && !errors.Is(err, api.ErrNotFound) {
256259
errCh <- fmt.Errorf("remove container '%s': %w", mc.Container.ID, err)
257260
}

0 commit comments

Comments
 (0)