summaryrefslogtreecommitdiff
path: root/libpod
diff options
context:
space:
mode:
authorbaude <bbaude@redhat.com>2018-12-01 09:49:46 -0600
committerbaude <bbaude@redhat.com>2018-12-05 19:57:54 -0600
commite037427035dc57e536478362fc19e30a400bc327 (patch)
tree3fb14dc437f58f29e197a43aaefa0e0254251f43 /libpod
parent75b19ca8abe1957f3c48035767960a6b20c10519 (diff)
downloadpodman-e037427035dc57e536478362fc19e30a400bc327.tar.gz
podman-e037427035dc57e536478362fc19e30a400bc327.tar.bz2
podman-e037427035dc57e536478362fc19e30a400bc327.zip
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 <bbaude@redhat.com>
Diffstat (limited to 'libpod')
-rw-r--r--libpod/image/prune.go26
1 files changed, 26 insertions, 0 deletions
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
+}