diff --git a/daemon/create.go b/daemon/create.go index 6d55028b72..c9da59d47c 100644 --- a/daemon/create.go +++ b/daemon/create.go @@ -19,6 +19,7 @@ func (daemon *Daemon) ContainerCreate(name string, config *runconfig.Config, hos return "", nil, fmt.Errorf("Config cannot be empty in order to create a container") } + daemon.adaptContainerSettings(hostConfig) warnings, err := daemon.verifyContainerSettings(hostConfig, config) if err != nil { return "", warnings, err diff --git a/daemon/daemon_unix.go b/daemon/daemon_unix.go index b3fe3848cd..97c504af31 100644 --- a/daemon/daemon_unix.go +++ b/daemon/daemon_unix.go @@ -114,6 +114,16 @@ func checkKernel() error { return nil } +func (daemon *Daemon) adaptContainerSettings(hostConfig *runconfig.HostConfig) { + if hostConfig == nil { + return + } + if hostConfig.Memory > 0 && hostConfig.MemorySwap == 0 { + // By default, MemorySwap is set to twice the size of Memory. + hostConfig.MemorySwap = hostConfig.Memory * 2 + } +} + func (daemon *Daemon) verifyContainerSettings(hostConfig *runconfig.HostConfig, config *runconfig.Config) ([]string, error) { var warnings []string diff --git a/daemon/daemon_windows.go b/daemon/daemon_windows.go index 1000beefc0..2dbd38889d 100644 --- a/daemon/daemon_windows.go +++ b/daemon/daemon_windows.go @@ -72,6 +72,10 @@ func checkKernel() error { return nil } +func (daemon *Daemon) adaptContainerSettings(hostConfig *runconfig.HostConfig) { + // TODO Windows. +} + func (daemon *Daemon) verifyContainerSettings(hostConfig *runconfig.HostConfig, config *runconfig.Config) ([]string, error) { // TODO Windows. Verifications TBC return nil, nil