瀏覽代碼

c8d/rmi: Handle explicit dangling name

This isn't something that user should do, but technically the dangling
images exist in the image store and user can pass its name (`moby-dangling@digest`).
Change it so rmi now recognizes that it's actually a dangling image and
doesn't handle it like a regular tagged image.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
Paweł Gronowski 1 年之前
父節點
當前提交
b8ba263099
共有 2 個文件被更改,包括 5 次插入2 次删除
  1. 2 1
      daemon/containerd/image_delete.go
  2. 3 1
      daemon/containerd/soft_delete.go

+ 2 - 1
daemon/containerd/image_delete.go

@@ -64,7 +64,8 @@ func (i *ImageService) ImageDelete(ctx context.Context, imageRef string, force,
 
 	imgID := image.ID(img.Target.Digest)
 
-	if isImageIDPrefix(imgID.String(), imageRef) {
+	explicitDanglingRef := strings.HasPrefix(imageRef, imageNameDanglingPrefix) && isDanglingImage(img)
+	if isImageIDPrefix(imgID.String(), imageRef) || explicitDanglingRef {
 		return i.deleteAll(ctx, img, force, prune)
 	}
 

+ 3 - 1
daemon/containerd/soft_delete.go

@@ -11,6 +11,8 @@ import (
 	"github.com/pkg/errors"
 )
 
+const imageNameDanglingPrefix = "moby-dangling@"
+
 // softImageDelete deletes the image, making sure that there are other images
 // that reference the content of the deleted image.
 // If no other image exists, a dangling one is created.
@@ -74,7 +76,7 @@ func (i *ImageService) ensureDanglingImage(ctx context.Context, from containerdi
 }
 
 func danglingImageName(digest digest.Digest) string {
-	return "moby-dangling@" + digest.String()
+	return imageNameDanglingPrefix + digest.String()
 }
 
 func isDanglingImage(image containerdimages.Image) bool {