runconfig

package
v0.3.3-0...-bb398fb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 15, 2015 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrConflictContainerNetworkAndLinks conflict between --net=container and links
	ErrConflictContainerNetworkAndLinks = fmt.Errorf("Conflicting options: container type network can't be used with links. This would result in undefined behavior")
	// ErrConflictUserDefinedNetworkAndLinks conflict between --net=<NETWORK> and links
	ErrConflictUserDefinedNetworkAndLinks = fmt.Errorf("Conflicting options: networking can't be used with links. This would result in undefined behavior")
	// ErrConflictSharedNetwork conflict between private and other networks
	ErrConflictSharedNetwork = fmt.Errorf("Container sharing network namespace with another container or host cannot be connected to any other network")
	// ErrConflictHostNetwork conflict from being disconnected from host network or connected to host network.
	ErrConflictHostNetwork = fmt.Errorf("Container cannot be disconnected from host network or connected to host network")
	// ErrConflictNoNetwork conflict between private and other networks
	ErrConflictNoNetwork = fmt.Errorf("Container cannot be connected to multiple networks with one of the networks in private (none) mode")
	// ErrConflictNetworkAndDNS conflict between --dns and the network mode
	ErrConflictNetworkAndDNS = fmt.Errorf("Conflicting options: dns and the network mode")
	// ErrConflictNetworkHostname conflict between the hostname and the network mode
	ErrConflictNetworkHostname = fmt.Errorf("Conflicting options: hostname and the network mode")
	// ErrConflictHostNetworkAndLinks conflict between --net=host and links
	ErrConflictHostNetworkAndLinks = fmt.Errorf("Conflicting options: host type networking can't be used with links. This would result in undefined behavior")
	// ErrConflictContainerNetworkAndMac conflict between the mac address and the network mode
	ErrConflictContainerNetworkAndMac = fmt.Errorf("Conflicting options: mac-address and the network mode")
	// ErrConflictNetworkHosts conflict between add-host and the network mode
	ErrConflictNetworkHosts = fmt.Errorf("Conflicting options: custom host-to-IP mapping and the network mode")
	// ErrConflictNetworkPublishPorts conflict between the publish options and the network mode
	ErrConflictNetworkPublishPorts = fmt.Errorf("Conflicting options: port publishing and the container type network mode")
	// ErrConflictNetworkExposePorts conflict between the expose option and the network mode
	ErrConflictNetworkExposePorts = fmt.Errorf("Conflicting options: port exposing and the container type network mode")
)

Functions

func Compare

func Compare(a, b *Config) bool

Compare two Config struct. Do not compare the "Image" nor "Hostname" fields If OpenStdin is set, then it differs

func ConvertKVStringsToMap

func ConvertKVStringsToMap(values []string) map[string]string

ConvertKVStringsToMap converts ["key=value"] to {"key":"value"}

func DecodeContainerConfig

func DecodeContainerConfig(src io.Reader) (*Config, *HostConfig, error)

DecodeContainerConfig decodes a json encoded config into a ContainerConfigWrapper struct and returns both a Config and an HostConfig struct Be aware this function is not checking whether the resulted structs are nil, it's your business to do so

func IsPreDefinedNetwork

func IsPreDefinedNetwork(network string) bool

IsPreDefinedNetwork indicates if a network is predefined by the daemon

func Merge

func Merge(userConf, imageConf *Config) error

Merge merges two Config, the image container configuration (defaults values), and the user container configuration, either passed by the API or generated by the cli. It will mutate the specified user configuration (userConf) with the image configuration where the user configuration is incomplete.

func Parse

func Parse(cmd *flag.FlagSet, args []string) (*Config, *HostConfig, *flag.FlagSet, error)

Parse parses the specified args for the specified command and generates a Config, a HostConfig and returns them with the specified command. If the specified args are not valid, it will return an error.

func ValidateIsolationLevel

func ValidateIsolationLevel(hc *HostConfig) error

ValidateIsolationLevel performs platform specific validation of the isolation level in the hostconfig structure. Linux only supports "default" which is LXC container isolation

func ValidateNetMode

func ValidateNetMode(c *Config, hc *HostConfig) error

ValidateNetMode ensures that the various combinations of requested network settings are valid.

Types

type Config

type Config struct {
	Hostname        string                // Hostname
	Domainname      string                // Domainname
	User            string                // User that will run the command(s) inside the container
	AttachStdin     bool                  // Attach the standard input, makes possible user interaction
	AttachStdout    bool                  // Attach the standard output
	AttachStderr    bool                  // Attach the standard error
	ExposedPorts    map[nat.Port]struct{} `json:",omitempty"` // List of exposed ports
	PublishService  string                `json:",omitempty"` // Name of the network service exposed by the container
	Tty             bool                  // Attach standard streams to a tty, including stdin if it is not closed.
	OpenStdin       bool                  // Open stdin
	StdinOnce       bool                  // If true, close stdin after the 1 attached client disconnects.
	Env             []string              // List of environment variable to set in the container
	Cmd             *stringutils.StrSlice // Command to run when starting the container
	ArgsEscaped     bool                  `json:",omitempty"` // True if command is already escaped (Windows specific)
	Image           string                // Name of the image as it was passed by the operator (eg. could be symbolic)
	Volumes         map[string]struct{}   // List of volumes (mounts) used for the container
	WorkingDir      string                // Current directory (PWD) in the command will be launched
	Entrypoint      *stringutils.StrSlice // Entrypoint to run when starting the container
	NetworkDisabled bool                  `json:",omitempty"` // Is network disabled
	MacAddress      string                `json:",omitempty"` // Mac Address of the container
	OnBuild         []string              // ONBUILD metadata that were defined on the image Dockerfile
	Labels          map[string]string     // List of labels set to this container
	StopSignal      string                `json:",omitempty"` // Signal to stop a container
}

Config contains the configuration data about a container. It should hold only portable information about the container. Here, "portable" means "independent from the host we are running on". Non-portable information *should* appear in HostConfig. All fields added to this struct must be marked `omitempty` to keep getting predictable hashes from the old `v1Compatibility` configuration.

type ContainerConfigWrapper

type ContainerConfigWrapper struct {
	*Config
	InnerHostConfig *HostConfig `json:"HostConfig,omitempty"`
	Cpuset          string      `json:",omitempty"` // Deprecated. Exported for backwards compatibility.
	*HostConfig                 // Deprecated. Exported to read attributes from json that are not in the inner host config structure.
}

ContainerConfigWrapper is a Config wrapper that hold the container Config (portable) and the corresponding HostConfig (non-portable).

func MergeConfigs

func MergeConfigs(config *Config, hostConfig *HostConfig) *ContainerConfigWrapper

MergeConfigs merges the specified container Config and HostConfig. It creates a ContainerConfigWrapper.

type DeviceMapping

type DeviceMapping struct {
	PathOnHost        string
	PathInContainer   string
	CgroupPermissions string
}

DeviceMapping represents the device mapping between the host and the container.

func ParseDevice

func ParseDevice(device string) (DeviceMapping, error)

ParseDevice parses a device mapping string to a DeviceMapping struct

type ExecConfig

type ExecConfig struct {
	User         string   // User that will run the command
	Privileged   bool     // Is the container in privileged mode
	Tty          bool     // Attach standard streams to a tty.
	Container    string   // Name of the container (to execute in)
	AttachStdin  bool     // Attach the standard input, makes possible user interaction
	AttachStderr bool     // Attach the standard output
	AttachStdout bool     // Attach the standard error
	Detach       bool     // Execute in detach mode
	Cmd          []string // Execution commands and args
}

ExecConfig is a small subset of the Config struct that hold the configuration for the exec feature of docker.

func ParseExec

func ParseExec(cmd *flag.FlagSet, args []string) (*ExecConfig, error)

ParseExec parses the specified args for the specified command and generates an ExecConfig from it. If the minimal number of specified args is not right or if specified args are not valid, it will return an error.

type HostConfig

type HostConfig struct {
	// Applicable to all platforms
	Binds           []string      // List of volume bindings for this container
	ContainerIDFile string        // File (path) where the containerId is written
	LogConfig       LogConfig     // Configuration of the logs for this container
	NetworkMode     NetworkMode   // Network mode to use for the container
	PortBindings    nat.PortMap   // Port mapping between the exposed port (container) and the host
	RestartPolicy   RestartPolicy // Restart policy to be used for the container
	VolumeDriver    string        // Name of the volume driver used to mount volumes
	VolumesFrom     []string      // List of volumes to take from other container

	// Applicable to UNIX platforms
	CapAdd          *stringutils.StrSlice // List of kernel capabilities to add to the container
	CapDrop         *stringutils.StrSlice // List of kernel capabilities to remove from the container
	DNS             []string              `json:"Dns"`        // List of DNS server to lookup
	DNSOptions      []string              `json:"DnsOptions"` // List of DNSOption to look for
	DNSSearch       []string              `json:"DnsSearch"`  // List of DNSSearch to look for
	ExtraHosts      []string              // List of extra hosts
	GroupAdd        []string              // List of additional groups that the container process will run as
	IpcMode         IpcMode               // IPC namespace to use for the container
	Links           []string              // List of links (in the name:alias form)
	OomScoreAdj     int                   // Container preference for OOM-killing
	OomKillDisable  bool                  // Whether to disable OOM Killer or not
	PidMode         PidMode               // PID namespace to use for the container
	Privileged      bool                  // Is the container in privileged mode
	PublishAllPorts bool                  // Should docker publish all exposed port for the container
	ReadonlyRootfs  bool                  // Is the container root filesystem in read-only
	SecurityOpt     []string              // List of string values to customize labels for MLS systems, such as SELinux.
	Tmpfs           map[string]string     `json:",omitempty"` // List of tmpfs (mounts) used for the container
	UTSMode         UTSMode               // UTS namespace to use for the container
	ShmSize         *int64                // Total shm memory usage

	// Applicable to Windows
	ConsoleSize [2]int         // Initial console size
	Isolation   IsolationLevel // Isolation level of the container (eg default, hyperv)

	// Contains container's resources (cgroups, ulimits)
	Resources
}

HostConfig the non-portable Config structure of a container. Here, "non-portable" means "dependent of the host we are running on". Portable information *should* appear in Config.

func DecodeHostConfig

func DecodeHostConfig(src io.Reader) (*HostConfig, error)

DecodeHostConfig creates a HostConfig based on the specified Reader. It assumes the content of the reader will be JSON, and decodes it.

func SetDefaultNetModeIfBlank

func SetDefaultNetModeIfBlank(hc *HostConfig) *HostConfig

SetDefaultNetModeIfBlank changes the NetworkMode in a HostConfig structure to default if it is not populated. This ensures backwards compatibility after the validation of the network mode was moved from the docker CLI to the docker daemon.

type IpcMode

type IpcMode string

IpcMode represents the container ipc stack.

func (IpcMode) Container

func (n IpcMode) Container() string

Container returns the name of the container ipc stack is going to be used.

func (IpcMode) IsContainer

func (n IpcMode) IsContainer() bool

IsContainer indicates whether the container uses a container's ipc stack.

func (IpcMode) IsHost

func (n IpcMode) IsHost() bool

IsHost indicates whether the container uses the host's ipc stack.

func (IpcMode) IsPrivate

func (n IpcMode) IsPrivate() bool

IsPrivate indicates whether the container uses it's private ipc stack.

func (IpcMode) Valid

func (n IpcMode) Valid() bool

Valid indicates whether the ipc stack is valid.

type IsolationLevel

type IsolationLevel string

IsolationLevel represents the isolation level of a container. The supported values are platform specific

func (IsolationLevel) IsDefault

func (i IsolationLevel) IsDefault() bool

IsDefault indicates the default isolation level of a container. On Linux this is the native driver. On Windows, this is a Windows Server Container.

func (IsolationLevel) IsValid

func (i IsolationLevel) IsValid() bool

IsValid indicates is an isolation level is valid

type KeyValuePair

type KeyValuePair struct {
	Key   string
	Value string
}

KeyValuePair is a structure that hold a value for a key.

type LogConfig

type LogConfig struct {
	Type   string
	Config map[string]string
}

LogConfig represents the logging configuration of the container.

type NetworkMode

type NetworkMode string

NetworkMode represents the container network stack.

func DefaultDaemonNetworkMode

func DefaultDaemonNetworkMode() NetworkMode

DefaultDaemonNetworkMode returns the default network stack the daemon should use.

func (NetworkMode) ConnectedContainer

func (n NetworkMode) ConnectedContainer() string

ConnectedContainer is the id of the container which network this container is connected to.

func (NetworkMode) IsBridge

func (n NetworkMode) IsBridge() bool

IsBridge indicates whether container uses the bridge network stack

func (NetworkMode) IsContainer

func (n NetworkMode) IsContainer() bool

IsContainer indicates whether container uses a container network stack.

func (NetworkMode) IsDefault

func (n NetworkMode) IsDefault() bool

IsDefault indicates whether container uses the default network stack.

func (NetworkMode) IsHost

func (n NetworkMode) IsHost() bool

IsHost indicates whether container uses the host network stack.

func (NetworkMode) IsNone

func (n NetworkMode) IsNone() bool

IsNone indicates whether container isn't using a network stack.

func (NetworkMode) IsPrivate

func (n NetworkMode) IsPrivate() bool

IsPrivate indicates whether container uses it's private network stack.

func (NetworkMode) IsUserDefined

func (n NetworkMode) IsUserDefined() bool

IsUserDefined indicates user-created network

func (NetworkMode) NetworkName

func (n NetworkMode) NetworkName() string

NetworkName returns the name of the network stack.

func (NetworkMode) UserDefined

func (n NetworkMode) UserDefined() string

UserDefined indicates user-created network

type PidMode

type PidMode string

PidMode represents the pid stack of the container.

func (PidMode) IsHost

func (n PidMode) IsHost() bool

IsHost indicates whether the container uses the host's pid stack.

func (PidMode) IsPrivate

func (n PidMode) IsPrivate() bool

IsPrivate indicates whether the container uses it's private pid stack.

func (PidMode) Valid

func (n PidMode) Valid() bool

Valid indicates whether the pid stack is valid.

type Resources

type Resources struct {
	// Applicable to all platforms
	CPUShares int64 `json:"CpuShares"` // CPU shares (relative weight vs. other containers)

	// Applicable to UNIX platforms
	CgroupParent        string // Parent cgroup.
	BlkioWeight         uint16 // Block IO weight (relative weight vs. other containers)
	BlkioWeightDevice   []*blkiodev.WeightDevice
	BlkioDeviceReadBps  []*blkiodev.ThrottleDevice
	BlkioDeviceWriteBps []*blkiodev.ThrottleDevice
	CPUPeriod           int64            `json:"CpuPeriod"` // CPU CFS (Completely Fair Scheduler) period
	CPUQuota            int64            `json:"CpuQuota"`  // CPU CFS (Completely Fair Scheduler) quota
	CpusetCpus          string           // CpusetCpus 0-2, 0,1
	CpusetMems          string           // CpusetMems 0-2, 0,1
	Devices             []DeviceMapping  // List of devices to map inside the container
	KernelMemory        int64            // Kernel memory limit (in bytes)
	Memory              int64            // Memory limit (in bytes)
	MemoryReservation   int64            // Memory soft limit (in bytes)
	MemorySwap          int64            // Total memory usage (memory + swap); set `-1` to disable swap
	MemorySwappiness    *int64           // Tuning container memory swappiness behaviour
	Ulimits             []*ulimit.Ulimit // List of ulimits to be set in the container
}

Resources contains container's resources (cgroups config, ulimits...)

type RestartPolicy

type RestartPolicy struct {
	Name              string
	MaximumRetryCount int
}

RestartPolicy represents the restart policies of the container.

func ParseRestartPolicy

func ParseRestartPolicy(policy string) (RestartPolicy, error)

ParseRestartPolicy returns the parsed policy or an error indicating what is incorrect

func (*RestartPolicy) IsAlways

func (rp *RestartPolicy) IsAlways() bool

IsAlways indicates whether the container has the "always" restart policy. This means the container will automatically restart regardless of the exit status.

func (*RestartPolicy) IsNone

func (rp *RestartPolicy) IsNone() bool

IsNone indicates whether the container has the "no" restart policy. This means the container will not automatically restart when exiting.

func (*RestartPolicy) IsOnFailure

func (rp *RestartPolicy) IsOnFailure() bool

IsOnFailure indicates whether the container has the "on-failure" restart policy. This means the contain will automatically restart of exiting with a non-zero exit status.

func (*RestartPolicy) IsUnlessStopped

func (rp *RestartPolicy) IsUnlessStopped() bool

IsUnlessStopped indicates whether the container has the "unless-stopped" restart policy. This means the container will automatically restart unless user has put it to stopped state.

type StreamConfig

type StreamConfig struct {
	// contains filtered or unexported fields
}

StreamConfig holds information about I/O streams managed together.

streamConfig.StdinPipe returns a WriteCloser which can be used to feed data to the standard input of the streamConfig's active process. streamConfig.StdoutPipe and streamConfig.StderrPipe each return a ReadCloser which can be used to retrieve the standard output (and error) generated by the container's active process. The output (and error) are actually copied and delivered to all StdoutPipe and StderrPipe consumers, using a kind of "broadcaster".

func NewStreamConfig

func NewStreamConfig() *StreamConfig

NewStreamConfig creates a stream config and initializes the standard err and standard out to new unbuffered broadcasters.

func (*StreamConfig) CloseStreams

func (streamConfig *StreamConfig) CloseStreams() error

CloseStreams ensures that the configured streams are properly closed.

func (*StreamConfig) NewInputPipes

func (streamConfig *StreamConfig) NewInputPipes()

NewInputPipes creates new pipes for both standard inputs, Stdin and StdinPipe.

func (*StreamConfig) NewNopInputPipe

func (streamConfig *StreamConfig) NewNopInputPipe()

NewNopInputPipe creates a new input pipe that will silently drop all messages in the input.

func (*StreamConfig) Stderr

func (streamConfig *StreamConfig) Stderr() *broadcaster.Unbuffered

Stderr returns the standard error in the configuration.

func (*StreamConfig) StderrPipe

func (streamConfig *StreamConfig) StderrPipe() io.ReadCloser

StderrPipe creates a new io.ReadCloser with an empty bytes pipe. It adds this new err pipe to the Stderr broadcaster.

func (*StreamConfig) Stdin

func (streamConfig *StreamConfig) Stdin() io.ReadCloser

Stdin returns the standard input in the configuration.

func (*StreamConfig) StdinPipe

func (streamConfig *StreamConfig) StdinPipe() io.WriteCloser

StdinPipe returns an input writer pipe as an io.WriteCloser.

func (*StreamConfig) Stdout

func (streamConfig *StreamConfig) Stdout() *broadcaster.Unbuffered

Stdout returns the standard output in the configuration.

func (*StreamConfig) StdoutPipe

func (streamConfig *StreamConfig) StdoutPipe() io.ReadCloser

StdoutPipe creates a new io.ReadCloser with an empty bytes pipe. It adds this new out pipe to the Stdout broadcaster.

type UTSMode

type UTSMode string

UTSMode represents the UTS namespace of the container.

func (UTSMode) IsHost

func (n UTSMode) IsHost() bool

IsHost indicates whether the container uses the host's UTS namespace.

func (UTSMode) IsPrivate

func (n UTSMode) IsPrivate() bool

IsPrivate indicates whether the container uses it's private UTS namespace.

func (UTSMode) Valid

func (n UTSMode) Valid() bool

Valid indicates whether the UTS namespace is valid.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL