docker: Index | Files

package container

import ""


Package Files

archive.go container.go container_unix.go history.go memory_store.go monitor.go state.go state_unix.go store.go


const DefaultSHMSize int64 = 67108864

DefaultSHMSize is the default size (64MB) of the SHM which will be mounted in the container

func AttachStreams Uses

func AttachStreams(streamConfig *runconfig.StreamConfig, openStdin, stdinOnce, tty bool, stdin io.ReadCloser, stdout io.Writer, stderr io.Writer, keys []byte) chan error

AttachStreams connects streams to a TTY. Used by exec too. Should this move somewhere else?

func IsValidStateString Uses

func IsValidStateString(s string) bool

IsValidStateString checks if the provided string is a valid container state or not.

type CommonContainer Uses

type CommonContainer struct {
    // embed for Container to support states directly.
    *State          `json:"State"` // Needed for remote api version <= 1.11
    Root            string         `json:"-"` // Path to the "home" of the container, including metadata.
    BaseFS          string         `json:"-"` // Path to the graphdriver mountpoint
    RWLayer         layer.RWLayer  `json:"-"`
    ID              string
    Created         time.Time
    Path            string
    Args            []string
    Config          *containertypes.Config
    ImageID         image.ID `json:"Image"`
    NetworkSettings *network.Settings
    LogPath         string
    Name            string
    Driver          string
    // MountLabel contains the options for the 'mount' command
    MountLabel             string
    ProcessLabel           string
    RestartCount           int
    HasBeenStartedBefore   bool
    HasBeenManuallyStopped bool // used for unless-stopped restart policy
    MountPoints            map[string]*volume.MountPoint
    HostConfig             *containertypes.HostConfig `json:"-"` // do not serialize the host config in the json, otherwise we'll make the container unportable
    Command                *execdriver.Command        `json:"-"`

    ExecCommands *exec.Store `json:"-"`
    // logDriver for closing
    LogDriver logger.Logger  `json:"-"`
    LogCopier *logger.Copier `json:"-"`
    // contains filtered or unexported fields

CommonContainer holds the fields for a container which are applicable across all platforms supported by the daemon.

type Container Uses

type Container struct {

    // Fields below here are platform specific.
    AppArmorProfile string
    HostnamePath    string
    HostsPath       string
    ShmPath         string
    MqueuePath      string
    ResolvConfPath  string
    SeccompProfile  string

Container holds the fields specific to unixen implementations. See CommonContainer for standard fields common to all containers.

func NewBaseContainer Uses

func NewBaseContainer(id, root string) *Container

NewBaseContainer creates a new container with its basic configuration.

func (*Container) AddBindMountPoint Uses

func (container *Container) AddBindMountPoint(name, source, destination string, rw bool)

AddBindMountPoint adds a new bind mount point configuration to the container.

func (*Container) AddLocalMountPoint Uses

func (container *Container) AddLocalMountPoint(name, destination string, rw bool)

AddLocalMountPoint adds a new local mount point configuration to the container.

func (*Container) AddMountPointWithVolume Uses

func (container *Container) AddMountPointWithVolume(destination string, vol volume.Volume, rw bool)

AddMountPointWithVolume adds a new mount point configured with a volume to the container.

func (*Container) Attach Uses

func (container *Container) Attach(stdin io.ReadCloser, stdout io.Writer, stderr io.Writer, keys []byte) chan error

Attach connects to the container's TTY, delegating to standard streams or websockets depending on the configuration.

func (*Container) BuildCreateEndpointOptions Uses

func (container *Container) BuildCreateEndpointOptions(n libnetwork.Network) ([]libnetwork.EndpointOption, error)

BuildCreateEndpointOptions builds endpoint options from a given network.

func (*Container) BuildEndpointInfo Uses

func (container *Container) BuildEndpointInfo(n libnetwork.Network, ep libnetwork.Endpoint) error

BuildEndpointInfo sets endpoint-related fields on container.NetworkSettings based on the provided network and endpoint.

func (*Container) BuildHostnameFile Uses

func (container *Container) BuildHostnameFile() error

BuildHostnameFile writes the container's hostname file.

func (*Container) BuildJoinOptions Uses

func (container *Container) BuildJoinOptions(n libnetwork.Network) ([]libnetwork.EndpointOption, error)

BuildJoinOptions builds endpoint Join options from a given network.

func (*Container) ConfigPath Uses

func (container *Container) ConfigPath() (string, error)

ConfigPath returns the path to the container's JSON config

func (*Container) CopyImagePathContent Uses

func (container *Container) CopyImagePathContent(v volume.Volume, destination string) error

CopyImagePathContent copies files in destination to the volume.

func (*Container) CreateDaemonEnvironment Uses

func (container *Container) CreateDaemonEnvironment(linkedEnv []string) []string

CreateDaemonEnvironment returns the list of all environment variables given the list of environment variables related to links. Sets PATH, HOSTNAME and if container.Config.Tty is set: TERM. The defaults set here do not override the values in container.Config.Env

func (*Container) ExitOnNext Uses

func (container *Container) ExitOnNext()

ExitOnNext signals to the monitor that it should not restart the container after we send the kill signal.

func (*Container) FromDisk Uses

func (container *Container) FromDisk() error

FromDisk loads the container configuration stored in the host.

func (*Container) GetEndpointInNetwork Uses

func (container *Container) GetEndpointInNetwork(n libnetwork.Network) (libnetwork.Endpoint, error)

GetEndpointInNetwork returns the container's endpoint to the provided network.

func (*Container) GetExecIDs Uses

func (container *Container) GetExecIDs() []string

GetExecIDs returns the list of exec commands running on the container.

func (*Container) GetLogConfig Uses

func (container *Container) GetLogConfig(defaultConfig containertypes.LogConfig) containertypes.LogConfig

GetLogConfig returns the log configuration for the container.

func (*Container) GetMountLabel Uses

func (container *Container) GetMountLabel() string

GetMountLabel returns the mounting label for the container. This label is empty if the container is privileged.

func (*Container) GetProcessLabel Uses

func (container *Container) GetProcessLabel() string

GetProcessLabel returns the process label for the container.

func (*Container) GetResourcePath Uses

func (container *Container) GetResourcePath(path string) (string, error)

GetResourcePath evaluates `path` in the scope of the container's BaseFS, with proper path sanitisation. Symlinks are all scoped to the BaseFS of the container, as though the container's BaseFS was `/`.

The BaseFS of a container is the host-facing path which is bind-mounted as `/` inside the container. This method is essentially used to access a particular path inside the container as though you were a process in that container.

NOTE: The returned path is *only* safely scoped inside the container's BaseFS

if no component of the returned path changes (such as a component
symlinking to a different path) between using this method and using the
path. See symlink.FollowSymlinkInScope for more details.

func (*Container) GetRootResourcePath Uses

func (container *Container) GetRootResourcePath(path string) (string, error)

GetRootResourcePath evaluates `path` in the scope of the container's root, with proper path sanitisation. Symlinks are all scoped to the root of the container, as though the container's root was `/`.

The root of a container is the host-facing configuration metadata directory. Only use this method to safely access the container's `container.json` or other metadata files. If in doubt, use container.GetResourcePath.

NOTE: The returned path is *only* safely scoped inside the container's root

if no component of the returned path changes (such as a component
symlinking to a different path) between using this method and using the
path. See symlink.FollowSymlinkInScope for more details.

func (*Container) HasMountFor Uses

func (container *Container) HasMountFor(path string) bool

HasMountFor checks if path is a mountpoint

func (*Container) HostConfigPath Uses

func (container *Container) HostConfigPath() (string, error)

HostConfigPath returns the path to the container's JSON hostconfig

func (*Container) InitDNSHostConfig Uses

func (container *Container) InitDNSHostConfig()

InitDNSHostConfig ensures that the dns fields are never nil. New containers don't ever have those fields nil, but pre created containers can still have those nil values. The non-recommended host configuration in the start api can make these fields nil again, this corrects that issue until we remove that behavior for good. See for a more detailed explanation on why we don't want that.

func (*Container) IpcMounts Uses

func (container *Container) IpcMounts() []execdriver.Mount

IpcMounts returns the list of IPC mounts

func (*Container) IsDestinationMounted Uses

func (container *Container) IsDestinationMounted(destination string) bool

IsDestinationMounted checks whether a path is mounted on the container or not.

func (*Container) MqueueResourcePath Uses

func (container *Container) MqueueResourcePath() (string, error)

MqueueResourcePath returns path to mqueue

func (*Container) NetworkMounts Uses

func (container *Container) NetworkMounts() []execdriver.Mount

NetworkMounts returns the list of network mounts.

func (*Container) Resize Uses

func (container *Container) Resize(h, w int) error

Resize changes the TTY of the process running inside the container to the given height and width. The container must be running.

func (*Container) ResolvePath Uses

func (container *Container) ResolvePath(path string) (resolvedPath, absPath string, err error)

ResolvePath resolves the given path in the container to a resource on the host. Returns a resolved path (absolute path to the resource on the host), the absolute path to the resource relative to the container's rootfs, and a error if the path points to outside the container's rootfs.

func (*Container) SetupWorkingDirectory Uses

func (container *Container) SetupWorkingDirectory() error

SetupWorkingDirectory sets up the container's working directory as set in container.Config.WorkingDir

func (*Container) ShmResourcePath Uses

func (container *Container) ShmResourcePath() (string, error)

ShmResourcePath returns path to shm

func (*Container) ShouldRestart Uses

func (container *Container) ShouldRestart() bool

ShouldRestart decides whether the daemon should restart the container or not. This is based on the container's restart policy.

func (*Container) StartLogger Uses

func (container *Container) StartLogger(cfg containertypes.LogConfig) (logger.Logger, error)

StartLogger starts a new logger driver for the container.

func (*Container) StartMonitor Uses

func (container *Container) StartMonitor(s supervisor, policy container.RestartPolicy) error

StartMonitor initializes a containerMonitor for this container with the provided supervisor and restart policy and starts the container's process.

func (*Container) StatPath Uses

func (container *Container) StatPath(resolvedPath, absPath string) (stat *types.ContainerPathStat, err error)

StatPath is the unexported version of StatPath. Locks and mounts should be acquired before calling this method and the given path should be fully resolved to a path on the host corresponding to the given absolute path inside the container.

func (*Container) StopSignal Uses

func (container *Container) StopSignal() int

StopSignal returns the signal used to stop the container.

func (*Container) TmpfsMounts Uses

func (container *Container) TmpfsMounts() []execdriver.Mount

TmpfsMounts returns the list of tmpfs mounts

func (*Container) ToDisk Uses

func (container *Container) ToDisk() error

ToDisk saves the container configuration on disk.

func (*Container) ToDiskLocking Uses

func (container *Container) ToDiskLocking() error

ToDiskLocking saves the container configuration on disk in a thread safe way.

func (*Container) TrySetNetworkMount Uses

func (container *Container) TrySetNetworkMount(destination string, path string) bool

TrySetNetworkMount attempts to set the network mounts given a provided destination and the path to use for it; return true if the given destination was a network mount file

func (*Container) UnmountIpcMounts Uses

func (container *Container) UnmountIpcMounts(unmount func(pth string) error)

UnmountIpcMounts uses the provided unmount function to unmount shm and mqueue if they were mounted

func (*Container) UnmountVolumes Uses

func (container *Container) UnmountVolumes(forceSyscall bool, volumeEventLog func(name, action string, attributes map[string]string)) error

UnmountVolumes unmounts all volumes

func (*Container) UpdateContainer Uses

func (container *Container) UpdateContainer(hostConfig *containertypes.HostConfig) error

UpdateContainer updates resources of a container.

func (*Container) UpdateJoinInfo Uses

func (container *Container) UpdateJoinInfo(n libnetwork.Network, ep libnetwork.Endpoint) error

UpdateJoinInfo updates network settings when container joins network n with endpoint ep.

func (*Container) UpdateSandboxNetworkSettings Uses

func (container *Container) UpdateSandboxNetworkSettings(sb libnetwork.Sandbox) error

UpdateSandboxNetworkSettings updates the sandbox ID and Key.

func (*Container) WriteHostConfig Uses

func (container *Container) WriteHostConfig() error

WriteHostConfig saves the host configuration on disk for the container.

type History Uses

type History []*Container

History is a convenience type for storing a list of containers, sorted by creation date in descendant order.

func (*History) Add Uses

func (history *History) Add(container *Container)

Add the given container to history.

func (*History) Len Uses

func (history *History) Len() int

Len returns the number of containers in the history.

func (*History) Less Uses

func (history *History) Less(i, j int) bool

Less compares two containers and returns true if the second one was created before the first one.

func (*History) Swap Uses

func (history *History) Swap(i, j int)

Swap switches containers i and j positions in the history.

type State Uses

type State struct {
    // FIXME: Why do we have both paused and running if a
    // container cannot be paused and running at the same time?
    Running           bool
    Paused            bool
    Restarting        bool
    OOMKilled         bool
    RemovalInProgress bool // Not need for this to be persistent on disk.
    Dead              bool
    Pid               int
    ExitCode          int
    Error             string // contains last known error when starting the container
    StartedAt         time.Time
    FinishedAt        time.Time
    // contains filtered or unexported fields

State holds the current container state, and has methods to get and set the state. Container has an embed, which allows all of the functions defined against State to run against Container.

func NewState Uses

func NewState() *State

NewState creates a default state object with a fresh channel for state changes.

func (*State) GetPID Uses

func (s *State) GetPID() int

GetPID holds the process id of a container.

func (*State) IsPaused Uses

func (s *State) IsPaused() bool

IsPaused returns whether the container is paused or not.

func (*State) IsRunning Uses

func (s *State) IsRunning() bool

IsRunning returns whether the running flag is set. Used by Container to check whether a container is running.

func (*State) ResetRemovalInProgress Uses

func (s *State) ResetRemovalInProgress()

ResetRemovalInProgress make the RemovalInProgress state to false.

func (*State) SetDead Uses

func (s *State) SetDead()

SetDead sets the container state to "dead"

func (*State) SetError Uses

func (s *State) SetError(err error)

SetError sets the container's error state. This is useful when we want to know the error that occurred when container transits to another state when inspecting it

func (*State) SetRemovalInProgress Uses

func (s *State) SetRemovalInProgress() error

SetRemovalInProgress sets the container state as being removed.

func (*State) SetRestarting Uses

func (s *State) SetRestarting(exitStatus *execdriver.ExitStatus)

SetRestarting sets the container state to "restarting". It also sets the container PID to 0.

func (*State) SetRestartingLocking Uses

func (s *State) SetRestartingLocking(exitStatus *execdriver.ExitStatus)

SetRestartingLocking is when docker handles the auto restart of containers when they are in the middle of a stop and being restarted again

func (*State) SetRunning Uses

func (s *State) SetRunning(pid int)

SetRunning sets the state of the container to "running".

func (*State) SetStopped Uses

func (s *State) SetStopped(exitStatus *execdriver.ExitStatus)

SetStopped sets the container state to "stopped" without locking.

func (*State) SetStoppedLocking Uses

func (s *State) SetStoppedLocking(exitStatus *execdriver.ExitStatus)

SetStoppedLocking locks the container state is sets it to "stopped".

func (*State) StateString Uses

func (s *State) StateString() string

StateString returns a single string to describe state

func (*State) String Uses

func (s *State) String() string

String returns a human-readable description of the state

func (*State) WaitStop Uses

func (s *State) WaitStop(timeout time.Duration) (int, error)

WaitStop waits until state is stopped. If state already stopped it returns immediately. If you want wait forever you must supply negative timeout. Returns exit code, that was passed to SetStoppedLocking

type Store Uses

type Store interface {
    // Add appends a new container to the store.
    Add(string, *Container)
    // Get returns a container from the store by the identifier it was stored with.
    Get(string) *Container
    // Delete removes a container from the store by the identifier it was stored with.
    // List returns a list of containers from the store.
    List() []*Container
    // Size returns the number of containers in the store.
    Size() int
    // First returns the first container found in the store by a given filter.
    First(StoreFilter) *Container
    // ApplyAll calls the reducer function with every container in the store.

Store defines an interface that any container store must implement.

func NewMemoryStore Uses

func NewMemoryStore() Store

NewMemoryStore initializes a new memory store.

type StoreFilter Uses

type StoreFilter func(*Container) bool

StoreFilter defines a function to filter container in the store.

type StoreReducer Uses

type StoreReducer func(*Container)

StoreReducer defines a function to manipulate containers in the store

Package container imports 44 packages (graph). Updated 2016-07-29. Refresh now. Tools for package owners. This is a dead-end fork (no commits since the fork).