github.com/akashshinde/docker@v1.9.1/runconfig/config.go (about)

     1  package runconfig
     2  
     3  import (
     4  	"encoding/json"
     5  	"io"
     6  
     7  	"github.com/docker/docker/pkg/nat"
     8  	"github.com/docker/docker/pkg/stringutils"
     9  )
    10  
    11  // Config contains the configuration data about a container.
    12  // It should hold only portable information about the container.
    13  // Here, "portable" means "independent from the host we are running on".
    14  // Non-portable information *should* appear in HostConfig.
    15  // All fields added to this struct must be marked `omitempty` to keep getting
    16  // predictable hashes from the old `v1Compatibility` configuration.
    17  type Config struct {
    18  	Hostname        string                // Hostname
    19  	Domainname      string                // Domainname
    20  	User            string                // User that will run the command(s) inside the container
    21  	AttachStdin     bool                  // Attach the standard input, makes possible user interaction
    22  	AttachStdout    bool                  // Attach the standard output
    23  	AttachStderr    bool                  // Attach the standard error
    24  	ExposedPorts    map[nat.Port]struct{} `json:",omitempty"` // List of exposed ports
    25  	PublishService  string                `json:",omitempty"` // Name of the network service exposed by the container
    26  	Tty             bool                  // Attach standard streams to a tty, including stdin if it is not closed.
    27  	OpenStdin       bool                  // Open stdin
    28  	StdinOnce       bool                  // If true, close stdin after the 1 attached client disconnects.
    29  	Env             []string              // List of environment variable to set in the container
    30  	Cmd             *stringutils.StrSlice // Command to run when starting the container
    31  	Image           string                // Name of the image as it was passed by the operator (eg. could be symbolic)
    32  	Volumes         map[string]struct{}   // List of volumes (mounts) used for the container
    33  	WorkingDir      string                // Current directory (PWD) in the command will be launched
    34  	Entrypoint      *stringutils.StrSlice // Entrypoint to run when starting the container
    35  	NetworkDisabled bool                  `json:",omitempty"` // Is network disabled
    36  	MacAddress      string                `json:",omitempty"` // Mac Address of the container
    37  	OnBuild         []string              // ONBUILD metadata that were defined on the image Dockerfile
    38  	Labels          map[string]string     // List of labels set to this container
    39  	StopSignal      string                `json:",omitempty"` // Signal to stop a container
    40  }
    41  
    42  // DecodeContainerConfig decodes a json encoded config into a ContainerConfigWrapper
    43  // struct and returns both a Config and an HostConfig struct
    44  // Be aware this function is not checking whether the resulted structs are nil,
    45  // it's your business to do so
    46  func DecodeContainerConfig(src io.Reader) (*Config, *HostConfig, error) {
    47  	decoder := json.NewDecoder(src)
    48  
    49  	var w ContainerConfigWrapper
    50  	if err := decoder.Decode(&w); err != nil {
    51  		return nil, nil, err
    52  	}
    53  
    54  	hc := w.getHostConfig()
    55  
    56  	// Certain parameters need daemon-side validation that cannot be done
    57  	// on the client, as only the daemon knows what is valid for the platform.
    58  	if err := ValidateNetMode(w.Config, hc); err != nil {
    59  		return nil, nil, err
    60  	}
    61  
    62  	return w.Config, hc, nil
    63  }