From d32f43013bf4c3aaa90c9ea409fbb9ade4105200 Mon Sep 17 00:00:00 2001 From: Tonis Tiigi Date: Wed, 30 Dec 2015 11:52:53 -0800 Subject: [PATCH] Fix missing comment in docker inspect Fixes #18571 Signed-off-by: Tonis Tiigi --- daemon/daemon.go | 7 ++++++- integration-cli/docker_cli_inspect_test.go | 9 +++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/daemon/daemon.go b/daemon/daemon.go index 70633debba..e8189f1732 100644 --- a/daemon/daemon.go +++ b/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{ ID: img.ID().String(), RepoTags: repoTags, RepoDigests: repoDigests, Parent: img.Parent.String(), - Comment: img.Comment, + Comment: comment, Created: img.Created.Format(time.RFC3339Nano), Container: img.Container, ContainerConfig: &img.ContainerConfig, diff --git a/integration-cli/docker_cli_inspect_test.go b/integration-cli/docker_cli_inspect_test.go index d471936be4..7f7d96986f 100644 --- a/integration-cli/docker_cli_inspect_test.go +++ b/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.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") +}