runconfig/config_unix.go
f6ed5905
 // +build !windows
 
4f0d95fa
 package runconfig // import "github.com/docker/docker/runconfig"
f6ed5905
 
2bb3fc1b
 import (
91e197d6
 	"github.com/docker/docker/api/types/container"
 	networktypes "github.com/docker/docker/api/types/network"
2bb3fc1b
 )
7ac4232e
 
34b82a69
 // ContainerConfigWrapper is a Config wrapper that holds the container Config (portable)
f6ed5905
 // and the corresponding HostConfig (non-portable).
 type ContainerConfigWrapper struct {
7ac4232e
 	*container.Config
2bb3fc1b
 	InnerHostConfig       *container.HostConfig          `json:"HostConfig,omitempty"`
 	Cpuset                string                         `json:",omitempty"` // Deprecated. Exported for backwards compatibility.
 	NetworkingConfig      *networktypes.NetworkingConfig `json:"NetworkingConfig,omitempty"`
 	*container.HostConfig                                // Deprecated. Exported to read attributes from json that are not in the inner host config structure.
f6ed5905
 }
 
 // getHostConfig gets the HostConfig of the Config.
 // It's mostly there to handle Deprecated fields of the ContainerConfigWrapper
7ac4232e
 func (w *ContainerConfigWrapper) getHostConfig() *container.HostConfig {
f6ed5905
 	hc := w.HostConfig
 
 	if hc == nil && w.InnerHostConfig != nil {
 		hc = w.InnerHostConfig
 	} else if w.InnerHostConfig != nil {
 		if hc.Memory != 0 && w.InnerHostConfig.Memory == 0 {
 			w.InnerHostConfig.Memory = hc.Memory
 		}
 		if hc.MemorySwap != 0 && w.InnerHostConfig.MemorySwap == 0 {
 			w.InnerHostConfig.MemorySwap = hc.MemorySwap
 		}
 		if hc.CPUShares != 0 && w.InnerHostConfig.CPUShares == 0 {
 			w.InnerHostConfig.CPUShares = hc.CPUShares
 		}
 		if hc.CpusetCpus != "" && w.InnerHostConfig.CpusetCpus == "" {
 			w.InnerHostConfig.CpusetCpus = hc.CpusetCpus
 		}
 
6549d651
 		if hc.VolumeDriver != "" && w.InnerHostConfig.VolumeDriver == "" {
 			w.InnerHostConfig.VolumeDriver = hc.VolumeDriver
 		}
 
f6ed5905
 		hc = w.InnerHostConfig
 	}
 
6549d651
 	if hc != nil {
 		if w.Cpuset != "" && hc.CpusetCpus == "" {
 			hc.CpusetCpus = w.Cpuset
 		}
f6ed5905
 	}
 
 	// Make sure NetworkMode has an acceptable value. We do this to ensure
927b334e
 	// backwards compatible API behavior.
7917a36c
 	SetDefaultNetModeIfBlank(hc)
f6ed5905
 
 	return hc
 }