Skip to content

Commit

Permalink
Do not prune images being used by a container
Browse files Browse the repository at this point in the history
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 <matthew.heon@pm.me>
  • Loading branch information
mheon committed Sep 10, 2019
1 parent c1761ba commit 3e92bcb
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions libpod/image/prune.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 3e92bcb

Please sign in to comment.