Prune named but untagged images if danglingOnly=true
@@ -135,18 +135,22 @@ func (daemon *Daemon) ImagesPrune(pruneFilters filters.Args) (*types.ImagesPrune
deletedImages := []types.ImageDelete{}
refs := daemon.referenceStore.References(dgst)
if len(refs) > 0 {
- if danglingOnly {
- // Not a dangling image
- continue
+ shouldDelete := !danglingOnly
+ if !shouldDelete {
+ hasTag := false
+ for _, ref := range refs {
+ if _, ok := ref.(reference.NamedTagged); ok {
+ hasTag = true
+ break
+ }
}
- nrRefs := len(refs)
- for _, ref := range refs {
- // If nrRefs == 1, we have an image marked as myreponame:<none>
- // i.e. the tag content was changed
- if _, ok := ref.(reference.Canonical); ok && nrRefs > 1 {
- continue
+ // Only delete if it's untagged (i.e. repo:<none>)
+ shouldDelete = !hasTag
}
+
+ if shouldDelete {
+ for _, ref := range refs {
imgDel, err := daemon.ImageDelete(ref.String(), false, true)
if err != nil {
logrus.Warnf("could not delete reference %s: %v", ref.String(), err)
@@ -154,6 +158,7 @@ func (daemon *Daemon) ImagesPrune(pruneFilters filters.Args) (*types.ImagesPrune
}
deletedImages = append(deletedImages, imgDel...)
}
+ }
} else {
imgDel, err := daemon.ImageDelete(hex, false, true)
if err != nil {
