github.com/christopherobin/docker@v1.6.2/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  // FIXME: we keep it for backward compatibility, it has been moved to hostConfig.
    16  	MemorySwap      int64  // FIXME: it has been moved to hostConfig.
    17  	CpuShares       int64  // FIXME: it has been moved to hostConfig.
    18  	Cpuset          string // FIXME: it has been moved to hostConfig and renamed to CpusetCpus.
    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  	Labels          map[string]string
    37  }
    38  
    39  func ContainerConfigFromJob(job *engine.Job) *Config {
    40  	config := &Config{
    41  		Hostname:        job.Getenv("Hostname"),
    42  		Domainname:      job.Getenv("Domainname"),
    43  		User:            job.Getenv("User"),
    44  		Memory:          job.GetenvInt64("Memory"),
    45  		MemorySwap:      job.GetenvInt64("MemorySwap"),
    46  		CpuShares:       job.GetenvInt64("CpuShares"),
    47  		Cpuset:          job.Getenv("Cpuset"),
    48  		AttachStdin:     job.GetenvBool("AttachStdin"),
    49  		AttachStdout:    job.GetenvBool("AttachStdout"),
    50  		AttachStderr:    job.GetenvBool("AttachStderr"),
    51  		Tty:             job.GetenvBool("Tty"),
    52  		OpenStdin:       job.GetenvBool("OpenStdin"),
    53  		StdinOnce:       job.GetenvBool("StdinOnce"),
    54  		Image:           job.Getenv("Image"),
    55  		WorkingDir:      job.Getenv("WorkingDir"),
    56  		NetworkDisabled: job.GetenvBool("NetworkDisabled"),
    57  		MacAddress:      job.Getenv("MacAddress"),
    58  	}
    59  	job.GetenvJson("ExposedPorts", &config.ExposedPorts)
    60  	job.GetenvJson("Volumes", &config.Volumes)
    61  	if PortSpecs := job.GetenvList("PortSpecs"); PortSpecs != nil {
    62  		config.PortSpecs = PortSpecs
    63  	}
    64  	if Env := job.GetenvList("Env"); Env != nil {
    65  		config.Env = Env
    66  	}
    67  	if Cmd := job.GetenvList("Cmd"); Cmd != nil {
    68  		config.Cmd = Cmd
    69  	}
    70  
    71  	job.GetenvJson("Labels", &config.Labels)
    72  
    73  	if Entrypoint := job.GetenvList("Entrypoint"); Entrypoint != nil {
    74  		config.Entrypoint = Entrypoint
    75  	}
    76  	return config
    77  }