github.com/endophage/docker@v1.4.2-0.20161027011718-242853499895/runconfig/hostconfig.go (about)

     1  package runconfig
     2  
     3  import (
     4  	"encoding/json"
     5  	"io"
     6  
     7  	"github.com/docker/docker/api/types/container"
     8  )
     9  
    10  // DecodeHostConfig creates a HostConfig based on the specified Reader.
    11  // It assumes the content of the reader will be JSON, and decodes it.
    12  func DecodeHostConfig(src io.Reader) (*container.HostConfig, error) {
    13  	decoder := json.NewDecoder(src)
    14  
    15  	var w ContainerConfigWrapper
    16  	if err := decoder.Decode(&w); err != nil {
    17  		return nil, err
    18  	}
    19  
    20  	hc := w.getHostConfig()
    21  	return hc, nil
    22  }
    23  
    24  // SetDefaultNetModeIfBlank changes the NetworkMode in a HostConfig structure
    25  // to default if it is not populated. This ensures backwards compatibility after
    26  // the validation of the network mode was moved from the docker CLI to the
    27  // docker daemon.
    28  func SetDefaultNetModeIfBlank(hc *container.HostConfig) *container.HostConfig {
    29  	if hc != nil {
    30  		if hc.NetworkMode == container.NetworkMode("") {
    31  			hc.NetworkMode = container.NetworkMode("default")
    32  		}
    33  	}
    34  	return hc
    35  }