Browse code

Merge pull request #29552 from dnephin/fix-build-with-log-driver

Ignore the daemon log config when building images

Daniel Nephin authored on 2017/02/08 05:47:41
Showing 5 changed files
... ...
@@ -49,6 +49,8 @@ var BuiltinAllowedBuildArgs = map[string]bool{
49 49
 	"no_proxy":    true,
50 50
 }
51 51
 
52
+var defaultLogConfig = container.LogConfig{Type: "none"}
53
+
52 54
 // Builder is a Dockerfile builder
53 55
 // It implements the builder.Backend interface.
54 56
 type Builder struct {
... ...
@@ -308,7 +308,11 @@ func workdir(b *Builder, args []string, attributes map[string]bool, original str
308 308
 		return nil
309 309
 	}
310 310
 
311
-	container, err := b.docker.ContainerCreate(types.ContainerCreateConfig{Config: b.runConfig})
311
+	container, err := b.docker.ContainerCreate(types.ContainerCreateConfig{
312
+		Config: b.runConfig,
313
+		// Set a log config to override any default value set on the daemon
314
+		HostConfig: &container.HostConfig{LogConfig: defaultLogConfig},
315
+	})
312 316
 	if err != nil {
313 317
 		return err
314 318
 	}
... ...
@@ -181,7 +181,11 @@ func (b *Builder) runContextCommand(args []string, allowRemote bool, allowLocalD
181 181
 		return nil
182 182
 	}
183 183
 
184
-	container, err := b.docker.ContainerCreate(types.ContainerCreateConfig{Config: b.runConfig})
184
+	container, err := b.docker.ContainerCreate(types.ContainerCreateConfig{
185
+		Config: b.runConfig,
186
+		// Set a log config to override any default value set on the daemon
187
+		HostConfig: &container.HostConfig{LogConfig: defaultLogConfig},
188
+	})
185 189
 	if err != nil {
186 190
 		return err
187 191
 	}
... ...
@@ -489,6 +493,8 @@ func (b *Builder) create() (string, error) {
489 489
 		ShmSize:     b.options.ShmSize,
490 490
 		Resources:   resources,
491 491
 		NetworkMode: container.NetworkMode(b.options.NetworkMode),
492
+		// Set a log config to override any default value set on the daemon
493
+		LogConfig: defaultLogConfig,
492 494
 	}
493 495
 
494 496
 	config := *b.runConfig
... ...
@@ -1,6 +1,6 @@
1 1
 package daemon
2 2
 
3
-// ContainerCreateWorkdir creates the working directory. This is solves the
3
+// ContainerCreateWorkdir creates the working directory. This solves the
4 4
 // issue arising from https://github.com/docker/docker/issues/27545,
5 5
 // which was initially fixed by https://github.com/docker/docker/pull/27884. But that fix
6 6
 // was too expensive in terms of performance on Windows. Instead,
... ...
@@ -1134,6 +1134,19 @@ func (s *DockerDaemonSuite) TestDaemonLoggingDriverNoneLogsError(c *check.C) {
1134 1134
 	c.Assert(out, checker.Contains, expected)
1135 1135
 }
1136 1136
 
1137
+func (s *DockerDaemonSuite) TestDaemonLoggingDriverShouldBeIgnoredForBuild(c *check.C) {
1138
+	s.d.StartWithBusybox(c, "--log-driver=splunk")
1139
+
1140
+	out, err := s.d.Cmd("build")
1141
+	out, code, err := s.d.BuildImageWithOut("busyboxs", `
1142
+        FROM busybox
1143
+        RUN echo foo`, false)
1144
+	comment := check.Commentf("Failed to build image. output %s, exitCode %d, err %v", out, code, err)
1145
+	c.Assert(err, check.IsNil, comment)
1146
+	c.Assert(code, check.Equals, 0, comment)
1147
+	c.Assert(out, checker.Contains, "foo", comment)
1148
+}
1149
+
1137 1150
 func (s *DockerDaemonSuite) TestDaemonUnixSockCleanedUp(c *check.C) {
1138 1151
 	dir, err := ioutil.TempDir("", "socket-cleanup-test")
1139 1152
 	if err != nil {