From 3e92bcbf7103c5469fdb37ca3d6aeb53ef93a48f Mon Sep 17 00:00:00 2001 From: Matthew Heon Date: Tue, 10 Sep 2019 13:26:30 -0400 Subject: Do not prune images being used by a container Podman is not the only user of containers/storage, and as such we cannot rely on our database as the sole source of truth when pruning images. If images do not show as in use from Podman's perspective, but subsequently fail to remove because they are being used by a container, they're probably being used by Buildah or another c/storage client. Since the images in question are in use, we shouldn't error on failure to prune them - we weren't supposed to prune them in the first place. Fixes: #3983 Signed-off-by: Matthew Heon --- libpod/image/prune.go | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'libpod/image/prune.go') diff --git a/libpod/image/prune.go b/libpod/image/prune.go index 6ef5d321f..006cbdf22 100644 --- a/libpod/image/prune.go +++ b/libpod/image/prune.go @@ -4,7 +4,9 @@ import ( "context" "github.com/containers/libpod/libpod/events" + "github.com/containers/storage" "github.com/pkg/errors" + "github.com/sirupsen/logrus" ) // GetPruneImages returns a slice of images that have no names/unused @@ -44,6 +46,10 @@ func (ir *Runtime) PruneImages(ctx context.Context, all bool) ([]string, error) } for _, p := range pruneImages { if err := p.Remove(ctx, true); err != nil { + if errors.Cause(err) == storage.ErrImageUsedByContainer { + logrus.Warnf("Failed to prune image %s as it is in use: %v", p.ID(), err) + continue + } return nil, errors.Wrap(err, "failed to prune image") } defer p.newImageEvent(events.Prune) -- cgit v1.2.3-54-g00ecf