瀏覽代碼

Merge pull request #19326 from HackToday/19153-filter-rethink

Fix image filter
Brian Goff 9 年之前
父節點
當前提交
7cd6210a88
共有 2 個文件被更改,包括 14 次插入1 次删除
  1. 5 1
      daemon/images.go
  2. 9 0
      integration-cli/docker_cli_images_test.go

+ 5 - 1
daemon/images.go

@@ -57,7 +57,6 @@ func (daemon *Daemon) Images(filterArgs, filter string, all bool) ([]*types.Imag
 			return nil, fmt.Errorf("Invalid filter 'dangling=%s'", imageFilters.Get("dangling"))
 		}
 	}
-
 	if danglingOnly {
 		allImages = daemon.imageStore.Heads()
 	} else {
@@ -124,6 +123,11 @@ func (daemon *Daemon) Images(filterArgs, filter string, all bool) ([]*types.Imag
 		}
 		if newImage.RepoDigests == nil && newImage.RepoTags == nil {
 			if all || len(daemon.imageStore.Children(id)) == 0 {
+
+				if imageFilters.Include("dangling") && !danglingOnly {
+					//dangling=false case, so dangling image is not needed
+					continue
+				}
 				if filter != "" { // skip images with no references if filtering by tag
 					continue
 				}

+ 9 - 0
integration-cli/docker_cli_images_test.go

@@ -176,6 +176,15 @@ func (s *DockerSuite) TestImagesEnsureDanglingImageOnlyListedOnce(c *check.C) {
 	out, _ = dockerCmd(c, "images", "-q", "-f", "dangling=true")
 	// Expect one dangling image
 	c.Assert(strings.Count(out, imageID), checker.Equals, 1)
+
+	out, _ = dockerCmd(c, "images", "-q", "-f", "dangling=false")
+	//dangling=false would not include dangling images
+	c.Assert(out, checker.Not(checker.Contains), imageID)
+
+	out, _ = dockerCmd(c, "images")
+	//docker images still include dangling images
+	c.Assert(out, checker.Contains, imageID)
+
 }
 
 func (s *DockerSuite) TestImagesWithIncorrectFilter(c *check.C) {