github.com/mheon/docker@v0.11.2-0.20150922122814-44f47903a831/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  type Config struct {
    16  	Hostname        string                // Hostname
    17  	Domainname      string                // Domainname
    18  	User            string                // User that will run the command(s) inside the container
    19  	AttachStdin     bool                  // Attach the standard input, makes possible user interaction
    20  	AttachStdout    bool                  // Attach the standard output
    21  	AttachStderr    bool                  // Attach the standard error
    22  	ExposedPorts    map[nat.Port]struct{} // List of exposed ports
    23  	PublishService  string                // Name of the network service exposed by the container
    24  	Tty             bool                  // Attach standard streams to a tty, including stdin if it is not closed.
    25  	OpenStdin       bool                  // Open stdin
    26  	StdinOnce       bool                  // If true, close stdin after the 1 attached client disconnects.
    27  	Env             []string              // List of environment variable to set in the container
    28  	Cmd             *stringutils.StrSlice // Command to run when starting the container
    29  	Image           string                // Name of the image as it was passed by the operator (eg. could be symbolic)
    30  	Volumes         map[string]struct{}   // List of volumes (mounts) used for the container
    31  	WorkingDir      string                // Current directory (PWD) in the command will be launched
    32  	Entrypoint      *stringutils.StrSlice // Entrypoint to run when starting the container
    33  	NetworkDisabled bool                  // Is network disabled
    34  	MacAddress      string                // Mac Address of the container
    35  	OnBuild         []string              // ONBUILD metadata that were defined on the image Dockerfile
    36  	Labels          map[string]string     // List of labels set to this container
    37  	StopSignal      string                // Signal to stop a container
    38  }
    39  
    40  // DecodeContainerConfig decodes a json encoded config into a ContainerConfigWrapper
    41  // struct and returns both a Config and an HostConfig struct
    42  // Be aware this function is not checking whether the resulted structs are nil,
    43  // it's your business to do so
    44  func DecodeContainerConfig(src io.Reader) (*Config, *HostConfig, error) {
    45  	decoder := json.NewDecoder(src)
    46  
    47  	var w ContainerConfigWrapper
    48  	if err := decoder.Decode(&w); err != nil {
    49  		return nil, nil, err
    50  	}
    51  
    52  	hc := w.getHostConfig()
    53  
    54  	// Certain parameters need daemon-side validation that cannot be done
    55  	// on the client, as only the daemon knows what is valid for the platform.
    56  	if err := ValidateNetMode(w.Config, hc); err != nil {
    57  		return nil, nil, err
    58  	}
    59  
    60  	return w.Config, hc, nil
    61  }