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)
}