github.com/yamamoto-febc/docker@v1.9.0/runconfig/config_unix.go (about) 1 // +build !windows 2 3 package runconfig 4 5 // ContainerConfigWrapper is a Config wrapper that hold the container Config (portable) 6 // and the corresponding HostConfig (non-portable). 7 type ContainerConfigWrapper struct { 8 *Config 9 InnerHostConfig *HostConfig `json:"HostConfig,omitempty"` 10 Cpuset string `json:",omitempty"` // Deprecated. Exported for backwards compatibility. 11 *HostConfig // Deprecated. Exported to read attributes from json that are not in the inner host config structure. 12 } 13 14 // getHostConfig gets the HostConfig of the Config. 15 // It's mostly there to handle Deprecated fields of the ContainerConfigWrapper 16 func (w *ContainerConfigWrapper) getHostConfig() *HostConfig { 17 hc := w.HostConfig 18 19 if hc == nil && w.InnerHostConfig != nil { 20 hc = w.InnerHostConfig 21 } else if w.InnerHostConfig != nil { 22 if hc.Memory != 0 && w.InnerHostConfig.Memory == 0 { 23 w.InnerHostConfig.Memory = hc.Memory 24 } 25 if hc.MemorySwap != 0 && w.InnerHostConfig.MemorySwap == 0 { 26 w.InnerHostConfig.MemorySwap = hc.MemorySwap 27 } 28 if hc.CPUShares != 0 && w.InnerHostConfig.CPUShares == 0 { 29 w.InnerHostConfig.CPUShares = hc.CPUShares 30 } 31 if hc.CpusetCpus != "" && w.InnerHostConfig.CpusetCpus == "" { 32 w.InnerHostConfig.CpusetCpus = hc.CpusetCpus 33 } 34 35 if hc.VolumeDriver != "" && w.InnerHostConfig.VolumeDriver == "" { 36 w.InnerHostConfig.VolumeDriver = hc.VolumeDriver 37 } 38 39 hc = w.InnerHostConfig 40 } 41 42 if hc != nil { 43 if w.Cpuset != "" && hc.CpusetCpus == "" { 44 hc.CpusetCpus = w.Cpuset 45 } 46 } 47 48 // Make sure NetworkMode has an acceptable value. We do this to ensure 49 // backwards compatible API behaviour. 50 hc = SetDefaultNetModeIfBlank(hc) 51 52 return hc 53 }