github.com/dlintw/docker@v1.5.0-rc4/runconfig/config.go (about)

     1  package runconfig
     2  
     3  import (
     4  	"github.com/docker/docker/engine"
     5  	"github.com/docker/docker/nat"
     6  )
     7  
     8  // Note: the Config structure should hold only portable information about the container.
     9  // Here, "portable" means "independent from the host we are running on".
    10  // Non-portable information *should* appear in HostConfig.
    11  type Config struct {
    12  	Hostname        string
    13  	Domainname      string
    14  	User            string
    15  	Memory          int64  // Memory limit (in bytes)
    16  	MemorySwap      int64  // Total memory usage (memory + swap); set `-1' to disable swap
    17  	CpuShares       int64  // CPU shares (relative weight vs. other containers)
    18  	Cpuset          string // Cpuset 0-2, 0,1
    19  	AttachStdin     bool
    20  	AttachStdout    bool
    21  	AttachStderr    bool
    22  	PortSpecs       []string // Deprecated - Can be in the format of 8080/tcp
    23  	ExposedPorts    map[nat.Port]struct{}
    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
    28  	Cmd             []string
    29  	Image           string // Name of the image as it was passed by the operator (eg. could be symbolic)
    30  	Volumes         map[string]struct{}
    31  	WorkingDir      string
    32  	Entrypoint      []string
    33  	NetworkDisabled bool
    34  	MacAddress      string
    35  	OnBuild         []string
    36  }
    37  
    38  func ContainerConfigFromJob(job *engine.Job) *Config {
    39  	config := &Config{
    40  		Hostname:        job.Getenv("Hostname"),
    41  		Domainname:      job.Getenv("Domainname"),
    42  		User:            job.Getenv("User"),
    43  		Memory:          job.GetenvInt64("Memory"),
    44  		MemorySwap:      job.GetenvInt64("MemorySwap"),
    45  		CpuShares:       job.GetenvInt64("CpuShares"),
    46  		Cpuset:          job.Getenv("Cpuset"),
    47  		AttachStdin:     job.GetenvBool("AttachStdin"),
    48  		AttachStdout:    job.GetenvBool("AttachStdout"),
    49  		AttachStderr:    job.GetenvBool("AttachStderr"),
    50  		Tty:             job.GetenvBool("Tty"),
    51  		OpenStdin:       job.GetenvBool("OpenStdin"),
    52  		StdinOnce:       job.GetenvBool("StdinOnce"),
    53  		Image:           job.Getenv("Image"),
    54  		WorkingDir:      job.Getenv("WorkingDir"),
    55  		NetworkDisabled: job.GetenvBool("NetworkDisabled"),
    56  		MacAddress:      job.Getenv("MacAddress"),
    57  	}
    58  	job.GetenvJson("ExposedPorts", &config.ExposedPorts)
    59  	job.GetenvJson("Volumes", &config.Volumes)
    60  	if PortSpecs := job.GetenvList("PortSpecs"); PortSpecs != nil {
    61  		config.PortSpecs = PortSpecs
    62  	}
    63  	if Env := job.GetenvList("Env"); Env != nil {
    64  		config.Env = Env
    65  	}
    66  	if Cmd := job.GetenvList("Cmd"); Cmd != nil {
    67  		config.Cmd = Cmd
    68  	}
    69  	if Entrypoint := job.GetenvList("Entrypoint"); Entrypoint != nil {
    70  		config.Entrypoint = Entrypoint
    71  	}
    72  	return config
    73  }