Fix missing comment in docker inspect

Fixes #18571

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
Tonis Tiigi 2015-12-30 11:52:53 -08:00
parent 51fa287368
commit d32f43013b
2 changed files with 15 additions and 1 deletions

View File

@ -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,

View File

@ -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")
}