diff --git a/pkg/client/deploy/operation.go b/pkg/client/deploy/operation.go index 7e458296..fee69cda 100644 --- a/pkg/client/deploy/operation.go +++ b/pkg/client/deploy/operation.go @@ -95,7 +95,10 @@ func (o *RemoveContainerOperation) Execute(ctx context.Context, cli Client) erro if err := cli.StopContainer(ctx, o.ServiceID, o.ContainerID, container.StopOptions{}); err != nil { return fmt.Errorf("stop container: %w", err) } - if err := cli.RemoveContainer(ctx, o.ServiceID, o.ContainerID, container.RemoveOptions{}); err != nil { + if err := cli.RemoveContainer(ctx, o.ServiceID, o.ContainerID, container.RemoveOptions{ + // Remove anonymous volumes created by the container. + RemoveVolumes: true, + }); err != nil { return fmt.Errorf("remove container: %w", err) } diff --git a/pkg/client/service.go b/pkg/client/service.go index fa1b4766..2b28dbd2 100644 --- a/pkg/client/service.go +++ b/pkg/client/service.go @@ -251,7 +251,10 @@ func (cli *Client) RemoveService(ctx context.Context, id string) error { return } - err = cli.RemoveContainer(ctx, svc.ID, mc.Container.ID, container.RemoveOptions{}) + err = cli.RemoveContainer(ctx, svc.ID, mc.Container.ID, container.RemoveOptions{ + // Remove anonymous volumes created by the container. + RemoveVolumes: true, + }) if err != nil && !errors.Is(err, api.ErrNotFound) { errCh <- fmt.Errorf("remove container '%s': %w", mc.Container.ID, err) }