From 2f2779b6a5c8f6efcd2ba55bf7cb0db54c259726 Mon Sep 17 00:00:00 2001 From: Brian Goff Date: Mon, 17 Aug 2015 11:35:34 -0400 Subject: [PATCH] Fix `inspect` output when no log driver specified Config options were being ignored in the inspect output when no driver was specified. Signed-off-by: Brian Goff --- daemon/inspect.go | 6 +++++- integration-cli/docker_cli_inspect_test.go | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/daemon/inspect.go b/daemon/inspect.go index 0bff1cba54..28fbe2b374 100644 --- a/daemon/inspect.go +++ b/daemon/inspect.go @@ -38,7 +38,11 @@ func (daemon *Daemon) getInspectData(container *Container) (*types.ContainerJSON // we need this trick to preserve empty log driver, so // container will use daemon defaults even if daemon change them if hostConfig.LogConfig.Type == "" { - hostConfig.LogConfig = daemon.defaultLogConfig + hostConfig.LogConfig.Type = daemon.defaultLogConfig.Type + } + + if hostConfig.LogConfig.Config == nil { + hostConfig.LogConfig.Config = daemon.defaultLogConfig.Config } containerState := &types.ContainerState{ diff --git a/integration-cli/docker_cli_inspect_test.go b/integration-cli/docker_cli_inspect_test.go index 1d5b7a6d42..2ad66f052c 100644 --- a/integration-cli/docker_cli_inspect_test.go +++ b/integration-cli/docker_cli_inspect_test.go @@ -1,6 +1,7 @@ package main import ( + "encoding/json" "fmt" "os/exec" "strconv" @@ -8,6 +9,7 @@ import ( "time" "github.com/docker/docker/api/types" + "github.com/docker/docker/runconfig" "github.com/go-check/check" ) @@ -286,3 +288,18 @@ func (s *DockerSuite) TestInspectTimesAsRFC3339Nano(c *check.C) { _, err = time.Parse(time.RFC3339Nano, created) c.Assert(err, check.IsNil) } + +// #15633 +func (s *DockerSuite) TestInspectLogConfigNoType(c *check.C) { + dockerCmd(c, "create", "--name=test", "--log-opt", "max-file=42", "busybox") + var logConfig runconfig.LogConfig + + out, err := inspectFieldJSON("test", "HostConfig.LogConfig") + c.Assert(err, check.IsNil) + + err = json.NewDecoder(strings.NewReader(out)).Decode(&logConfig) + c.Assert(err, check.IsNil) + + c.Assert(logConfig.Type, check.Equals, "json-file") + c.Assert(logConfig.Config["max-file"], check.Equals, "42", check.Commentf("%v", logConfig)) +}