Browse code

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 <cpuguy83@gmail.com>

Brian Goff authored on 2015/08/18 00:35:34
Showing 2 changed files
... ...
@@ -38,7 +38,11 @@ func (daemon *Daemon) getInspectData(container *Container) (*types.ContainerJSON
38 38
 	// we need this trick to preserve empty log driver, so
39 39
 	// container will use daemon defaults even if daemon change them
40 40
 	if hostConfig.LogConfig.Type == "" {
41
-		hostConfig.LogConfig = daemon.defaultLogConfig
41
+		hostConfig.LogConfig.Type = daemon.defaultLogConfig.Type
42
+	}
43
+
44
+	if hostConfig.LogConfig.Config == nil {
45
+		hostConfig.LogConfig.Config = daemon.defaultLogConfig.Config
42 46
 	}
43 47
 
44 48
 	containerState := &types.ContainerState{
... ...
@@ -1,6 +1,7 @@
1 1
 package main
2 2
 
3 3
 import (
4
+	"encoding/json"
4 5
 	"fmt"
5 6
 	"os/exec"
6 7
 	"strconv"
... ...
@@ -8,6 +9,7 @@ import (
8 8
 	"time"
9 9
 
10 10
 	"github.com/docker/docker/api/types"
11
+	"github.com/docker/docker/runconfig"
11 12
 	"github.com/go-check/check"
12 13
 )
13 14
 
... ...
@@ -286,3 +288,18 @@ func (s *DockerSuite) TestInspectTimesAsRFC3339Nano(c *check.C) {
286 286
 	_, err = time.Parse(time.RFC3339Nano, created)
287 287
 	c.Assert(err, check.IsNil)
288 288
 }
289
+
290
+// #15633
291
+func (s *DockerSuite) TestInspectLogConfigNoType(c *check.C) {
292
+	dockerCmd(c, "create", "--name=test", "--log-opt", "max-file=42", "busybox")
293
+	var logConfig runconfig.LogConfig
294
+
295
+	out, err := inspectFieldJSON("test", "HostConfig.LogConfig")
296
+	c.Assert(err, check.IsNil)
297
+
298
+	err = json.NewDecoder(strings.NewReader(out)).Decode(&logConfig)
299
+	c.Assert(err, check.IsNil)
300
+
301
+	c.Assert(logConfig.Type, check.Equals, "json-file")
302
+	c.Assert(logConfig.Config["max-file"], check.Equals, "42", check.Commentf("%v", logConfig))
303
+}