github.com/ssdev-go/moby@v17.12.1-ce-rc2+incompatible/runconfig/config.go (about) 1 package runconfig 2 3 import ( 4 "encoding/json" 5 "io" 6 7 "github.com/docker/docker/api/types/container" 8 networktypes "github.com/docker/docker/api/types/network" 9 "github.com/docker/docker/pkg/sysinfo" 10 ) 11 12 // ContainerDecoder implements httputils.ContainerDecoder 13 // calling DecodeContainerConfig. 14 type ContainerDecoder struct{} 15 16 // DecodeConfig makes ContainerDecoder to implement httputils.ContainerDecoder 17 func (r ContainerDecoder) DecodeConfig(src io.Reader) (*container.Config, *container.HostConfig, *networktypes.NetworkingConfig, error) { 18 return decodeContainerConfig(src) 19 } 20 21 // DecodeHostConfig makes ContainerDecoder to implement httputils.ContainerDecoder 22 func (r ContainerDecoder) DecodeHostConfig(src io.Reader) (*container.HostConfig, error) { 23 return decodeHostConfig(src) 24 } 25 26 // decodeContainerConfig decodes a json encoded config into a ContainerConfigWrapper 27 // struct and returns both a Config and a HostConfig struct 28 // Be aware this function is not checking whether the resulted structs are nil, 29 // it's your business to do so 30 func decodeContainerConfig(src io.Reader) (*container.Config, *container.HostConfig, *networktypes.NetworkingConfig, error) { 31 var w ContainerConfigWrapper 32 33 decoder := json.NewDecoder(src) 34 if err := decoder.Decode(&w); err != nil { 35 return nil, nil, nil, err 36 } 37 38 hc := w.getHostConfig() 39 40 // Perform platform-specific processing of Volumes and Binds. 41 if w.Config != nil && hc != nil { 42 43 // Initialize the volumes map if currently nil 44 if w.Config.Volumes == nil { 45 w.Config.Volumes = make(map[string]struct{}) 46 } 47 } 48 49 // Certain parameters need daemon-side validation that cannot be done 50 // on the client, as only the daemon knows what is valid for the platform. 51 if err := validateNetMode(w.Config, hc); err != nil { 52 return nil, nil, nil, err 53 } 54 55 // Validate isolation 56 if err := validateIsolation(hc); err != nil { 57 return nil, nil, nil, err 58 } 59 60 // Validate QoS 61 if err := validateQoS(hc); err != nil { 62 return nil, nil, nil, err 63 } 64 65 // Validate Resources 66 if err := validateResources(hc, sysinfo.New(true)); err != nil { 67 return nil, nil, nil, err 68 } 69 70 // Validate Privileged 71 if err := validatePrivileged(hc); err != nil { 72 return nil, nil, nil, err 73 } 74 75 // Validate ReadonlyRootfs 76 if err := validateReadonlyRootfs(hc); err != nil { 77 return nil, nil, nil, err 78 } 79 80 return w.Config, hc, w.NetworkingConfig, nil 81 }