Make sure container start doesn't make the DNS fields nil.
| ... | ... |
@@ -166,22 +166,7 @@ func (container *Container) readHostConfig() error {
|
| 166 | 166 |
return err |
| 167 | 167 |
} |
| 168 | 168 |
|
| 169 |
- // Make sure the dns fields are never nil. |
|
| 170 |
- // New containers don't ever have those fields nil, |
|
| 171 |
- // but pre created containers can still have those nil values. |
|
| 172 |
- // See https://github.com/docker/docker/pull/17779 |
|
| 173 |
- // for a more detailed explanation on why we don't want that. |
|
| 174 |
- if container.hostConfig.DNS == nil {
|
|
| 175 |
- container.hostConfig.DNS = make([]string, 0) |
|
| 176 |
- } |
|
| 177 |
- |
|
| 178 |
- if container.hostConfig.DNSSearch == nil {
|
|
| 179 |
- container.hostConfig.DNSSearch = make([]string, 0) |
|
| 180 |
- } |
|
| 181 |
- |
|
| 182 |
- if container.hostConfig.DNSOptions == nil {
|
|
| 183 |
- container.hostConfig.DNSOptions = make([]string, 0) |
|
| 184 |
- } |
|
| 169 |
+ initDNSHostConfig(container) |
|
| 185 | 170 |
|
| 186 | 171 |
return nil |
| 187 | 172 |
} |
| ... | ... |
@@ -543,3 +528,25 @@ func (container *Container) stopSignal() int {
|
| 543 | 543 |
} |
| 544 | 544 |
return int(stopSignal) |
| 545 | 545 |
} |
| 546 |
+ |
|
| 547 |
+// initDNSHostConfig ensures that the dns fields are never nil. |
|
| 548 |
+// New containers don't ever have those fields nil, |
|
| 549 |
+// but pre created containers can still have those nil values. |
|
| 550 |
+// The non-recommended host configuration in the start api can |
|
| 551 |
+// make these fields nil again, this corrects that issue until |
|
| 552 |
+// we remove that behavior for good. |
|
| 553 |
+// See https://github.com/docker/docker/pull/17779 |
|
| 554 |
+// for a more detailed explanation on why we don't want that. |
|
| 555 |
+func initDNSHostConfig(container *Container) {
|
|
| 556 |
+ if container.hostConfig.DNS == nil {
|
|
| 557 |
+ container.hostConfig.DNS = make([]string, 0) |
|
| 558 |
+ } |
|
| 559 |
+ |
|
| 560 |
+ if container.hostConfig.DNSSearch == nil {
|
|
| 561 |
+ container.hostConfig.DNSSearch = make([]string, 0) |
|
| 562 |
+ } |
|
| 563 |
+ |
|
| 564 |
+ if container.hostConfig.DNSOptions == nil {
|
|
| 565 |
+ container.hostConfig.DNSOptions = make([]string, 0) |
|
| 566 |
+ } |
|
| 567 |
+} |
| ... | ... |
@@ -29,6 +29,7 @@ func (daemon *Daemon) ContainerStart(name string, hostConfig *runconfig.HostConf |
| 29 | 29 |
// This is kept for backward compatibility - hostconfig should be passed when |
| 30 | 30 |
// creating a container, not during start. |
| 31 | 31 |
if hostConfig != nil {
|
| 32 |
+ logrus.Warn("DEPRECATED: Setting host configuration options when the container starts is deprecated and will be removed in Docker 1.12")
|
|
| 32 | 33 |
container.Lock() |
| 33 | 34 |
if err := parseSecurityOpt(container, hostConfig); err != nil {
|
| 34 | 35 |
container.Unlock() |
| ... | ... |
@@ -38,6 +39,7 @@ func (daemon *Daemon) ContainerStart(name string, hostConfig *runconfig.HostConf |
| 38 | 38 |
if err := daemon.setHostConfig(container, hostConfig); err != nil {
|
| 39 | 39 |
return err |
| 40 | 40 |
} |
| 41 |
+ initDNSHostConfig(container) |
|
| 41 | 42 |
} |
| 42 | 43 |
} else {
|
| 43 | 44 |
if hostConfig != nil {
|
| ... | ... |
@@ -1371,3 +1371,20 @@ func (s *DockerSuite) TestPostContainersCreateWithWrongCpusetValues(c *check.C) |
| 1371 | 1371 |
expected = "Invalid value 42-3,1-- for cpuset mems.\n" |
| 1372 | 1372 |
c.Assert(string(body), checker.Equals, expected) |
| 1373 | 1373 |
} |
| 1374 |
+ |
|
| 1375 |
+func (s *DockerSuite) TestStartWithNilDNS(c *check.C) {
|
|
| 1376 |
+ testRequires(c, DaemonIsLinux) |
|
| 1377 |
+ out, _ := dockerCmd(c, "create", "busybox") |
|
| 1378 |
+ containerID := strings.TrimSpace(out) |
|
| 1379 |
+ |
|
| 1380 |
+ config := `{"HostConfig": {"Dns": null}}`
|
|
| 1381 |
+ |
|
| 1382 |
+ res, b, err := sockRequestRaw("POST", "/containers/"+containerID+"/start", strings.NewReader(config), "application/json")
|
|
| 1383 |
+ c.Assert(err, checker.IsNil) |
|
| 1384 |
+ c.Assert(res.StatusCode, checker.Equals, http.StatusNoContent) |
|
| 1385 |
+ b.Close() |
|
| 1386 |
+ |
|
| 1387 |
+ dns, err := inspectFieldJSON(containerID, "HostConfig.Dns") |
|
| 1388 |
+ c.Assert(err, checker.IsNil) |
|
| 1389 |
+ c.Assert(dns, checker.Equals, "[]") |
|
| 1390 |
+} |