diff options
author | baude <bbaude@redhat.com> | 2018-12-01 09:49:46 -0600 |
---|---|---|
committer | baude <bbaude@redhat.com> | 2018-12-05 19:57:54 -0600 |
commit | e037427035dc57e536478362fc19e30a400bc327 (patch) | |
tree | 3fb14dc437f58f29e197a43aaefa0e0254251f43 /libpod/image | |
parent | 75b19ca8abe1957f3c48035767960a6b20c10519 (diff) | |
download | podman-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/image')
-rw-r--r-- | libpod/image/prune.go | 26 |
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 +} |