diff --git a/cmd/podman/system/reset.go b/cmd/podman/system/reset.go index 89c7e2dbf3..81f1126849 100644 --- a/cmd/podman/system/reset.go +++ b/cmd/podman/system/reset.go @@ -48,10 +48,9 @@ func init() { func reset(cmd *cobra.Command, args []string) { // Get all the external containers in use - listCtn, _ := registry.ContainerEngine().ContainerListExternal(registry.Context()) - listCtnIds := make([]string, 0, len(listCtn)) - for _, externalCtn := range listCtn { - listCtnIds = append(listCtnIds, externalCtn.ID) + listCtn, err := registry.ContainerEngine().ContainerListExternal(registry.Context()) + if err != nil { + logrus.Error(err) } // Prompt for confirmation if --force is not set if !forceFlag { @@ -90,14 +89,8 @@ func reset(cmd *cobra.Command, args []string) { } } - // Purge all the external containers with storage - _, err := registry.ContainerEngine().ContainerRm(registry.Context(), listCtnIds, entities.RmOptions{Force: true, All: true, Ignore: true, Volumes: true}) - if err != nil { - logrus.Error(err) - } // Clean build cache if any - err = volumes.CleanCacheMount() - if err != nil { + if err := volumes.CleanCacheMount(); err != nil { logrus.Error(err) } // Shutdown all running engines, `reset` will hijack repository diff --git a/libpod/reset.go b/libpod/reset.go index db82ae53d8..8a0fea19eb 100644 --- a/libpod/reset.go +++ b/libpod/reset.go @@ -117,13 +117,23 @@ func (r *Runtime) reset(ctx context.Context) error { } for _, c := range ctrs { - if err := r.RemoveContainer(ctx, c, true, true, timeout); err != nil { - if err := r.RemoveStorageContainer(c.ID(), true); err != nil { - if errors.Is(err, define.ErrNoSuchCtr) { - continue - } - logrus.Errorf("Removing container %s: %v", c.ID(), err) + if ctrs, _, err := r.RemoveContainerAndDependencies(ctx, c, true, true, timeout); err != nil { + for ctr, err := range ctrs { + logrus.Errorf("Error removing container %s: %v", ctr, err) } + + if errors.Is(err, define.ErrNoSuchCtr) || errors.Is(err, define.ErrCtrRemoved) { + continue + } + + logrus.Errorf("Removing container %s: %v", c.ID(), err) + + // There's no point trying a storage container removal + // here. High likelihood it doesn't work + // (RemoveStorageContainer will refuse to remove if a + // container exists in the Libpod database) and, even if + // it would, we'll get the container later on during + // image removal. } } @@ -131,11 +141,7 @@ func (r *Runtime) reset(ctx context.Context) error { logrus.Errorf("Stopping pause process: %v", err) } - rmiOptions := &libimage.RemoveImagesOptions{Filters: []string{"readonly=false"}} - if _, rmiErrors := r.LibimageRuntime().RemoveImages(ctx, nil, rmiOptions); rmiErrors != nil { - return errorhandling.JoinErrors(rmiErrors) - } - + // Volumes before images, as volumes can mount images. volumes, err := r.state.AllVolumes() if err != nil { return err @@ -149,6 +155,19 @@ func (r *Runtime) reset(ctx context.Context) error { } } + // Set force and ignore. + // Ignore shouldn't be necessary, but it seems safer. We want everything + // gone anyways... + rmiOptions := &libimage.RemoveImagesOptions{ + Force: true, + Ignore: true, + RemoveContainerFunc: r.RemoveContainersForImageCallback(ctx), + Filters: []string{"readonly=false"}, + } + if _, rmiErrors := r.LibimageRuntime().RemoveImages(ctx, nil, rmiOptions); rmiErrors != nil { + return errorhandling.JoinErrors(rmiErrors) + } + // remove all networks nets, err := r.network.NetworkList() if err != nil {