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