diff --git a/daemon/daemon_unix.go b/daemon/daemon_unix.go index 13ac51843b..9e2d6736d5 100644 --- a/daemon/daemon_unix.go +++ b/daemon/daemon_unix.go @@ -155,6 +155,8 @@ func verifyPlatformContainerSettings(daemon *Daemon, hostConfig *runconfig.HostC if hostConfig.LxcConf.Len() > 0 && !strings.Contains(daemon.ExecutionDriver().Name(), "lxc") { return warnings, fmt.Errorf("Cannot use --lxc-conf with execdriver: %s", daemon.ExecutionDriver().Name()) } + + // memory subsystem checks and adjustments if hostConfig.Memory != 0 && hostConfig.Memory < 4194304 { return warnings, fmt.Errorf("Minimum memory limit allowed is 4MB") } @@ -162,6 +164,7 @@ func verifyPlatformContainerSettings(daemon *Daemon, hostConfig *runconfig.HostC warnings = append(warnings, "Your kernel does not support memory limit capabilities. Limitation discarded.") logrus.Warnf("Your kernel does not support memory limit capabilities. Limitation discarded.") hostConfig.Memory = 0 + hostConfig.MemorySwap = -1 } if hostConfig.Memory > 0 && hostConfig.MemorySwap != -1 && !sysInfo.SwapLimit { warnings = append(warnings, "Your kernel does not support swap limit capabilities, memory limited without swap.") @@ -174,7 +177,7 @@ func verifyPlatformContainerSettings(daemon *Daemon, hostConfig *runconfig.HostC if hostConfig.Memory == 0 && hostConfig.MemorySwap > 0 { return warnings, fmt.Errorf("You should always set the Memory limit when using Memoryswap limit, see usage.") } - if hostConfig.MemorySwappiness != nil && !sysInfo.MemorySwappiness { + if hostConfig.MemorySwappiness != nil && *hostConfig.MemorySwappiness != -1 && !sysInfo.MemorySwappiness { warnings = append(warnings, "Your kernel does not support memory swappiness capabilities, memory swappiness discarded.") logrus.Warnf("Your kernel does not support memory swappiness capabilities, memory swappiness discarded.") hostConfig.MemorySwappiness = nil @@ -198,10 +201,12 @@ func verifyPlatformContainerSettings(daemon *Daemon, hostConfig *runconfig.HostC if hostConfig.BlkioWeight > 0 && (hostConfig.BlkioWeight < 10 || hostConfig.BlkioWeight > 1000) { return warnings, fmt.Errorf("Range of blkio weight is from 10 to 1000.") } + if hostConfig.OomKillDisable && !sysInfo.OomKillDisable { hostConfig.OomKillDisable = false return warnings, fmt.Errorf("Your kernel does not support oom kill disable.") } + if sysInfo.IPv4ForwardingDisabled { warnings = append(warnings, "IPv4 forwarding is disabled. Networking will not work.") logrus.Warnf("IPv4 forwarding is disabled. Networking will not work") diff --git a/daemon/start.go b/daemon/start.go index 9df56c5a34..2dc05d613c 100644 --- a/daemon/start.go +++ b/daemon/start.go @@ -21,10 +21,6 @@ func (daemon *Daemon) ContainerStart(name string, hostConfig *runconfig.HostConf return fmt.Errorf("Container already started") } - if _, err = daemon.verifyContainerSettings(hostConfig, nil); err != nil { - return err - } - // Windows does not have the backwards compatibilty issue here. if runtime.GOOS != "windows" { // This is kept for backward compatibility - hostconfig should be passed when @@ -40,6 +36,12 @@ func (daemon *Daemon) ContainerStart(name string, hostConfig *runconfig.HostConf } } + // check if hostConfig is in line with the current system settings. + // It may happen cgroups are umounted or the like. + if _, err = daemon.verifyContainerSettings(container.hostConfig, nil); err != nil { + return err + } + if err := container.Start(); err != nil { return fmt.Errorf("Cannot start container %s: %s", name, err) } diff --git a/runconfig/parse.go b/runconfig/parse.go index 5528d7af76..6488817cfd 100644 --- a/runconfig/parse.go +++ b/runconfig/parse.go @@ -188,16 +188,16 @@ func Parse(cmd *flag.FlagSet, args []string) (*Config, *HostConfig, *flag.FlagSe flMemory = parsedMemory } - var MemorySwap int64 + var memorySwap int64 if *flMemorySwap != "" { if *flMemorySwap == "-1" { - MemorySwap = -1 + memorySwap = -1 } else { parsedMemorySwap, err := units.RAMInBytes(*flMemorySwap) if err != nil { return nil, nil, cmd, err } - MemorySwap = parsedMemorySwap + memorySwap = parsedMemorySwap } } @@ -354,7 +354,7 @@ func Parse(cmd *flag.FlagSet, args []string) (*Config, *HostConfig, *flag.FlagSe ContainerIDFile: *flContainerIDFile, LxcConf: lxcConf, Memory: flMemory, - MemorySwap: MemorySwap, + MemorySwap: memorySwap, CPUShares: *flCPUShares, CPUPeriod: *flCPUPeriod, CpusetCpus: *flCpusetCpus,