podman rmi: improve error message for build containers

Improve the error message when attempting to remove an image that is in
use by an external/build container.  Prior, the error only indicated
that the image was in use but did not aid in resolving the issue.

Fixes: #15006
Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
This commit is contained in:
Valentin Rothberg
2022-08-04 16:42:02 +02:00
parent 4dff697b77
commit 3102194f03
7 changed files with 18 additions and 10 deletions

View File

@ -470,6 +470,9 @@ func (i *Image) removeRecursive(ctx context.Context, rmMap map[string]*RemoveIma
}
if _, err := i.runtime.store.DeleteImage(i.ID(), true); handleError(err) != nil {
if errors.Is(err, storage.ErrImageUsedByContainer) {
err = fmt.Errorf("%w: consider listing external containers and force-removing image", err)
}
return processedIDs, err
}
report.Untagged = append(report.Untagged, i.Names()...)
@ -478,6 +481,11 @@ func (i *Image) removeRecursive(ctx context.Context, rmMap map[string]*RemoveIma
report.Removed = true
}
// Do not delete any parents if NoPrune is true
if options.NoPrune {
return processedIDs, nil
}
// Check if can remove the parent image.
if parent == nil {
return processedIDs, nil
@ -495,7 +503,6 @@ func (i *Image) removeRecursive(ctx context.Context, rmMap map[string]*RemoveIma
if !danglingParent {
return processedIDs, nil
}
// Recurse into removing the parent.
return parent.removeRecursive(ctx, rmMap, processedIDs, "", options)
}

View File

@ -608,6 +608,8 @@ type RemoveImagesOptions struct {
// much space was freed. However, computing the size of an image is
// comparatively expensive, so it is made optional.
WithSize bool
// NoPrune will not remove dangling images
NoPrune bool
}
// RemoveImages removes images specified by names. If no names are specified,
@ -653,7 +655,6 @@ func (r *Runtime) RemoveImages(ctx context.Context, names []string, options *Rem
toDelete := []string{}
// Look up images in the local containers storage and fill out
// toDelete and the deleteMap.
switch {
case len(names) > 0:
// prepare lookupOptions

View File

@ -1,4 +1,4 @@
package version
// Version is the version of the build.
const Version = "0.49.1-dev"
const Version = "0.49.2-dev"