diff --git a/daemon/images.go b/daemon/images.go index 2b2a994b1e..e4c3797f6d 100644 --- a/daemon/images.go +++ b/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 } diff --git a/integration-cli/docker_cli_images_test.go b/integration-cli/docker_cli_images_test.go index c44b9e1ce3..dbceddf14e 100644 --- a/integration-cli/docker_cli_images_test.go +++ b/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) {