Browse Source

Merge pull request #18999 from tonistiigi/fix-comment-in-inspect

Fix missing comment in docker inspect
David Calavera 9 năm trước cách đây
mục cha
commit
102eb03c68

+ 6 - 1
daemon/daemon.go

@@ -1170,12 +1170,17 @@ func (daemon *Daemon) LookupImage(name string) (*types.ImageInspect, error) {
 		}
 		}
 	}
 	}
 
 
+	comment := img.Comment
+	if len(comment) == 0 && len(img.History) > 0 {
+		comment = img.History[len(img.History)-1].Comment
+	}
+
 	imageInspect := &types.ImageInspect{
 	imageInspect := &types.ImageInspect{
 		ID:              img.ID().String(),
 		ID:              img.ID().String(),
 		RepoTags:        repoTags,
 		RepoTags:        repoTags,
 		RepoDigests:     repoDigests,
 		RepoDigests:     repoDigests,
 		Parent:          img.Parent.String(),
 		Parent:          img.Parent.String(),
-		Comment:         img.Comment,
+		Comment:         comment,
 		Created:         img.Created.Format(time.RFC3339Nano),
 		Created:         img.Created.Format(time.RFC3339Nano),
 		Container:       img.Container,
 		Container:       img.Container,
 		ContainerConfig: &img.ContainerConfig,
 		ContainerConfig: &img.ContainerConfig,

+ 9 - 0
integration-cli/docker_cli_inspect_test.go

@@ -372,3 +372,12 @@ func (s *DockerSuite) TestInspectStopWhenNotFound(c *check.C) {
 	c.Assert(out, checker.Not(checker.Contains), "not-shown")
 	c.Assert(out, checker.Not(checker.Contains), "not-shown")
 	c.Assert(out, checker.Contains, "Error: No such container: missing")
 	c.Assert(out, checker.Contains, "Error: No such container: missing")
 }
 }
+
+func (s *DockerSuite) TestInspectHistory(c *check.C) {
+	dockerCmd(c, "run", "--name=testcont", "-d", "busybox", "top")
+	dockerCmd(c, "commit", "-m", "test comment", "testcont", "testimg")
+	out, _, err := dockerCmdWithError("inspect", "--format='{{.Comment}}'", "testimg")
+
+	c.Assert(err, check.IsNil)
+	c.Assert(out, checker.Contains, "test comment")
+}