From e037427035dc57e536478362fc19e30a400bc327 Mon Sep 17 00:00:00 2001 From: baude Date: Sat, 1 Dec 2018 09:49:46 -0600 Subject: Add ability to prune containers and images Allow user to prune unused/unnamed images, the layer images from building, via podman rmi --prune. Allow user to prune stopped/exiuted containers via podman rm --prune. This should resolve #1910 Signed-off-by: baude --- libpod/image/prune.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 libpod/image/prune.go (limited to 'libpod/image/prune.go') diff --git a/libpod/image/prune.go b/libpod/image/prune.go new file mode 100644 index 000000000..6a1f160d5 --- /dev/null +++ b/libpod/image/prune.go @@ -0,0 +1,26 @@ +package image + +// GetPruneImages returns a slice of images that have no names/unused +func (ir *Runtime) GetPruneImages() ([]*Image, error) { + var ( + unamedImages []*Image + ) + allImages, err := ir.GetImages() + if err != nil { + return nil, err + } + for _, i := range allImages { + if len(i.Names()) == 0 { + unamedImages = append(unamedImages, i) + continue + } + containers, err := i.Containers() + if err != nil { + return nil, err + } + if len(containers) < 1 { + unamedImages = append(unamedImages, i) + } + } + return unamedImages, nil +} -- cgit v1.2.3-54-g00ecf