diff --git a/api/client/run.go b/api/client/run.go index dcd7f01f6b..1fd392c04d 100644 --- a/api/client/run.go +++ b/api/client/run.go @@ -90,7 +90,7 @@ func (cli *DockerCli) CmdRun(args ...string) error { os.Exit(125) } - if hostConfig.OomKillDisable && hostConfig.Memory == 0 { + if hostConfig.OomKillDisable != nil && *hostConfig.OomKillDisable && hostConfig.Memory == 0 { fmt.Fprintf(cli.err, "WARNING: Dangerous only disable the OOM Killer on containers but not set the '-m/--memory' option\n") } diff --git a/daemon/container_operations_unix.go b/daemon/container_operations_unix.go index 4ee9e5f44c..dd99900e35 100644 --- a/daemon/container_operations_unix.go +++ b/daemon/container_operations_unix.go @@ -209,7 +209,7 @@ func (daemon *Daemon) populateCommand(c *container.Container, env []string) erro BlkioThrottleWriteBpsDevice: writeBpsDevice, BlkioThrottleReadIOpsDevice: readIOpsDevice, BlkioThrottleWriteIOpsDevice: writeIOpsDevice, - OomKillDisable: c.HostConfig.OomKillDisable, + OomKillDisable: *c.HostConfig.OomKillDisable, MemorySwappiness: -1, } diff --git a/daemon/daemon_unix.go b/daemon/daemon_unix.go index 89c23c558c..8928fd64f6 100644 --- a/daemon/daemon_unix.go +++ b/daemon/daemon_unix.go @@ -210,6 +210,10 @@ func (daemon *Daemon) adaptContainerSettings(hostConfig *containertypes.HostConf defaultSwappiness := int64(-1) hostConfig.MemorySwappiness = &defaultSwappiness } + if hostConfig.OomKillDisable == nil { + defaultOomKillDisable := false + hostConfig.OomKillDisable = &defaultOomKillDisable + } return nil } @@ -270,8 +274,8 @@ func verifyContainerResources(resources *containertypes.Resources) ([]string, er warnings = append(warnings, "You specified a kernel memory limit on a kernel older than 4.0. Kernel memory limits are experimental on older kernels, it won't work as expected and can cause your system to be unstable.") logrus.Warnf("You specified a kernel memory limit on a kernel older than 4.0. Kernel memory limits are experimental on older kernels, it won't work as expected and can cause your system to be unstable.") } - if resources.OomKillDisable && !sysInfo.OomKillDisable { - resources.OomKillDisable = false + if resources.OomKillDisable != nil && !sysInfo.OomKillDisable { + resources.OomKillDisable = nil return warnings, fmt.Errorf("Your kernel does not support oom kill disable.") } diff --git a/runconfig/opts/parse.go b/runconfig/opts/parse.go index b27b9b5721..d78e8f0810 100644 --- a/runconfig/opts/parse.go +++ b/runconfig/opts/parse.go @@ -327,7 +327,7 @@ func Parse(cmd *flag.FlagSet, args []string) (*container.Config, *container.Host MemorySwap: memorySwap, MemorySwappiness: flSwappiness, KernelMemory: KernelMemory, - OomKillDisable: *flOomKillDisable, + OomKillDisable: flOomKillDisable, CPUShares: *flCPUShares, CPUPeriod: *flCPUPeriod, CpusetCpus: *flCpusetCpus,