Documentation ¶
Index ¶
- Constants
- func AttachStreams(ctx context.Context, streamConfig *stream.Config, ...) chan error
- func GetSandboxPortMapInfo(sb libnetwork.Sandbox) nat.PortMap
- func IsValidHealthString(s string) bool
- func IsValidStateString(s string) bool
- func ReplaceOrAppendEnvValues(defaults, overrides []string) []string
- type CommonContainer
- type Container
- func (container *Container) AddMountPointWithVolume(destination string, vol volume.Volume, rw bool)
- func (container *Container) Attach(stdin io.ReadCloser, stdout io.Writer, stderr io.Writer, keys []byte) chan error
- func (container *Container) BuildCreateEndpointOptions(n libnetwork.Network, epConfig *networktypes.EndpointSettings, ...) ([]libnetwork.EndpointOption, error)
- func (container *Container) BuildEndpointInfo(n libnetwork.Network, ep libnetwork.Endpoint) error
- func (container *Container) BuildHostnameFile() error
- func (container *Container) BuildJoinOptions(n libnetwork.Network) ([]libnetwork.EndpointOption, error)
- func (container *Container) CancelAttachContext()
- func (container *Container) CheckpointDir() string
- func (container *Container) CloseStreams() error
- func (container *Container) ConfigPath() (string, error)
- func (container *Container) CopyImagePathContent(v volume.Volume, destination string) error
- func (container *Container) CreateDaemonEnvironment(tty bool, linkedEnv []string) []string
- func (container *Container) DetachAndUnmount(volumeEventLog func(name, action string, attributes map[string]string)) error
- func (container *Container) EnableServiceDiscoveryOnDefaultNetwork() bool
- func (container *Container) ExitOnNext()
- func (container *Container) FromDisk() error
- func (container *Container) FullHostname() string
- func (container *Container) GetEndpointInNetwork(n libnetwork.Network) (libnetwork.Endpoint, error)
- func (container *Container) GetExecIDs() []string
- func (container *Container) GetMountLabel() string
- func (container *Container) GetProcessLabel() string
- func (container *Container) GetResourcePath(path string) (string, error)
- func (container *Container) GetRootResourcePath(path string) (string, error)
- func (container *Container) HasMountFor(path string) bool
- func (container *Container) HostConfigPath() (string, error)
- func (container *Container) InitAttachContext() context.Context
- func (container *Container) InitDNSHostConfig()
- func (container *Container) InitializeStdio(iop libcontainerd.IOPipe) error
- func (container *Container) IpcMounts() []Mount
- func (container *Container) IsDestinationMounted(destination string) bool
- func (container *Container) NetworkMounts() []Mount
- func (container *Container) Reset(lock bool)
- func (container *Container) ResetRestartManager(resetCount bool)
- func (container *Container) ResolvePath(path string) (resolvedPath, absPath string, err error)
- func (container *Container) RestartManager() restartmanager.RestartManager
- func (container *Container) SecretMount() *Mount
- func (container *Container) SecretMountPath() string
- func (container *Container) SetupWorkingDirectory(rootUID, rootGID int) error
- func (container *Container) ShmResourcePath() (string, error)
- func (container *Container) ShouldRestart() bool
- func (container *Container) StartLogger() (logger.Logger, error)
- func (container *Container) StatPath(resolvedPath, absPath string) (stat *types.ContainerPathStat, err error)
- func (container *Container) StderrPipe() io.ReadCloser
- func (container *Container) StdinPipe() io.WriteCloser
- func (container *Container) StdoutPipe() io.ReadCloser
- func (container *Container) StopSignal() int
- func (container *Container) StopTimeout() int
- func (container *Container) TmpfsMounts() ([]Mount, error)
- func (container *Container) ToDisk() error
- func (container *Container) ToDiskLocking() error
- func (container *Container) TrySetNetworkMount(destination string, path string) bool
- func (container *Container) UnmountIpcMounts(unmount func(pth string) error)
- func (container *Container) UnmountSecrets() error
- func (container *Container) UnmountVolumes(volumeEventLog func(name, action string, attributes map[string]string)) error
- func (container *Container) UpdateContainer(hostConfig *containertypes.HostConfig) error
- func (container *Container) UpdateJoinInfo(n libnetwork.Network, ep libnetwork.Endpoint) error
- func (container *Container) UpdateMonitor(restartPolicy containertypes.RestartPolicy)
- func (container *Container) UpdateSandboxNetworkSettings(sb libnetwork.Sandbox) error
- func (container *Container) WriteHostConfig() error
- type DetachError
- type ExitStatus
- type Health
- type History
- type Mount
- type State
- func (s *State) Error() string
- func (s *State) ExitCode() int
- func (s *State) GetPID() int
- func (s *State) HealthString() string
- func (s *State) IsPaused() bool
- func (s *State) IsRestarting() bool
- func (s *State) IsRunning() bool
- func (s *State) ResetRemovalInProgress()
- func (s *State) SetDead()
- func (s *State) SetError(err error)
- func (s *State) SetExitCode(ec int)
- func (s *State) SetRemovalInProgress() bool
- func (s *State) SetRestarting(exitStatus *ExitStatus)
- func (s *State) SetRunning(pid int, initial bool)
- func (s *State) SetStopped(exitStatus *ExitStatus)
- func (s *State) StateString() string
- func (s *State) String() string
- func (s *State) WaitStop(timeout time.Duration) (int, error)
- func (s *State) WaitWithContext(ctx context.Context) error
- type StateStatus
- type Store
- type StoreFilter
- type StoreReducer
Constants ¶
const ( // DefaultSHMSize is the default size (64MB) of the SHM which will be mounted in the container DefaultSHMSize int64 = 67108864 )
const (
// DefaultStopTimeout is the timeout (in seconds) for the syscall signal used to stop a container.
DefaultStopTimeout = 10
)
Variables ¶
This section is empty.
Functions ¶
func AttachStreams ¶
func AttachStreams(ctx context.Context, streamConfig *stream.Config, 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 GetSandboxPortMapInfo ¶
func GetSandboxPortMapInfo(sb libnetwork.Sandbox) nat.PortMap
GetSandboxPortMapInfo retrieves the current port-mapping programmed for the given sandbox
func IsValidHealthString ¶
IsValidHealthString checks if the provided string is a valid container health status or not.
func IsValidStateString ¶
IsValidStateString checks if the provided string is a valid container state or not.
func ReplaceOrAppendEnvValues ¶
ReplaceOrAppendEnvValues returns the defaults with the overrides either replaced by env key or appended to the list
Types ¶
type CommonContainer ¶
type CommonContainer struct { StreamConfig *stream.Config // embed for Container to support states directly. *State `json:"State"` // Needed for Engine 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 Managed bool 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 ExecCommands *exec.Store `json:"-"` SecretStore agentexec.SecretGetter `json:"-"` SecretReferences []*swarmtypes.SecretReference // 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 ¶
type Container struct { CommonContainer // Fields below here are platform specific. AppArmorProfile string HostnamePath string HostsPath string ShmPath string ResolvConfPath string SeccompProfile string NoNewPrivileges bool }
Container holds the fields specific to unixen implementations. See CommonContainer for standard fields common to all containers.
func NewBaseContainer ¶
NewBaseContainer creates a new container with its basic configuration.
func (*Container) AddMountPointWithVolume ¶
AddMountPointWithVolume adds a new mount point configured with a volume to the container.
func (*Container) Attach ¶
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 ¶
func (container *Container) BuildCreateEndpointOptions(n libnetwork.Network, epConfig *networktypes.EndpointSettings, sb libnetwork.Sandbox, daemonDNS []string) ([]libnetwork.EndpointOption, error)
BuildCreateEndpointOptions builds endpoint options from a given network.
func (*Container) BuildEndpointInfo ¶
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 ¶
BuildHostnameFile writes the container's hostname file.
func (*Container) BuildJoinOptions ¶
func (container *Container) BuildJoinOptions(n libnetwork.Network) ([]libnetwork.EndpointOption, error)
BuildJoinOptions builds endpoint Join options from a given network.
func (*Container) CancelAttachContext ¶
func (container *Container) CancelAttachContext()
CancelAttachContext cancels attach context. All attach calls should detach after this call.
func (*Container) CheckpointDir ¶
CheckpointDir returns the directory checkpoints are stored in
func (*Container) CloseStreams ¶
CloseStreams closes the container's stdio streams
func (*Container) ConfigPath ¶
ConfigPath returns the path to the container's JSON config
func (*Container) CopyImagePathContent ¶
CopyImagePathContent copies files in destination to the volume.
func (*Container) CreateDaemonEnvironment ¶
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) DetachAndUnmount ¶
func (container *Container) DetachAndUnmount(volumeEventLog func(name, action string, attributes map[string]string)) error
DetachAndUnmount uses a detached mount on all mount destinations, then unmounts each volume normally. This is used from daemon/archive for `docker cp`
func (*Container) EnableServiceDiscoveryOnDefaultNetwork ¶
EnableServiceDiscoveryOnDefaultNetwork Enable service discovery on default network
func (*Container) ExitOnNext ¶
func (container *Container) ExitOnNext()
ExitOnNext signals to the monitor that it should not restart the container after we send the kill signal.
func (*Container) FullHostname ¶
FullHostname returns hostname and optional domain appended to it.
func (*Container) GetEndpointInNetwork ¶
func (container *Container) GetEndpointInNetwork(n libnetwork.Network) (libnetwork.Endpoint, error)
GetEndpointInNetwork returns the container's endpoint to the provided network.
func (*Container) GetExecIDs ¶
GetExecIDs returns the list of exec commands running on the container.
func (*Container) GetMountLabel ¶
GetMountLabel returns the mounting label for the container. This label is empty if the container is privileged.
func (*Container) GetProcessLabel ¶
GetProcessLabel returns the process label for the container.
func (*Container) GetResourcePath ¶
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 ¶
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 ¶
HasMountFor checks if path is a mountpoint
func (*Container) HostConfigPath ¶
HostConfigPath returns the path to the container's JSON hostconfig
func (*Container) InitAttachContext ¶
InitAttachContext initializes or returns existing context for attach calls to track container liveness.
func (*Container) InitDNSHostConfig ¶
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 https://github.com/docker/docker/pull/17779 for a more detailed explanation on why we don't want that.
func (*Container) InitializeStdio ¶
func (container *Container) InitializeStdio(iop libcontainerd.IOPipe) error
InitializeStdio is called by libcontainerd to connect the stdio.
func (*Container) IsDestinationMounted ¶
IsDestinationMounted checks whether a path is mounted on the container or not.
func (*Container) NetworkMounts ¶
NetworkMounts returns the list of network mounts.
func (*Container) ResetRestartManager ¶
ResetRestartManager initializes new restartmanager based on container config
func (*Container) ResolvePath ¶
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 an error if the path points to outside the container's rootfs.
func (*Container) RestartManager ¶
func (container *Container) RestartManager() restartmanager.RestartManager
RestartManager returns the current restartmanager instance connected to container.
func (*Container) SecretMount ¶
SecretMount returns the mount for the secret path
func (*Container) SecretMountPath ¶
SecretMountPath returns the path of the secret mount for the container
func (*Container) SetupWorkingDirectory ¶
SetupWorkingDirectory sets up the container's working directory as set in container.Config.WorkingDir
func (*Container) ShmResourcePath ¶
ShmResourcePath returns path to shm
func (*Container) ShouldRestart ¶
ShouldRestart decides whether the daemon should restart the container or not. This is based on the container's restart policy.
func (*Container) StartLogger ¶
StartLogger starts a new logger driver for the container.
func (*Container) StatPath ¶
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) StderrPipe ¶
func (container *Container) StderrPipe() io.ReadCloser
StderrPipe gets the stderr stream of the container
func (*Container) StdinPipe ¶
func (container *Container) StdinPipe() io.WriteCloser
StdinPipe gets the stdin stream of the container
func (*Container) StdoutPipe ¶
func (container *Container) StdoutPipe() io.ReadCloser
StdoutPipe gets the stdout stream of the container
func (*Container) StopSignal ¶
StopSignal returns the signal used to stop the container.
func (*Container) StopTimeout ¶
StopTimeout returns the timeout (in seconds) used to stop the container.
func (*Container) TmpfsMounts ¶
TmpfsMounts returns the list of tmpfs mounts
func (*Container) ToDiskLocking ¶
ToDiskLocking saves the container configuration on disk in a thread safe way.
func (*Container) TrySetNetworkMount ¶
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 ¶
UnmountIpcMounts uses the provided unmount function to unmount shm and mqueue if they were mounted
func (*Container) UnmountSecrets ¶
UnmountSecrets unmounts the local tmpfs for secrets
func (*Container) UnmountVolumes ¶
func (container *Container) UnmountVolumes(volumeEventLog func(name, action string, attributes map[string]string)) error
UnmountVolumes unmounts all volumes
func (*Container) UpdateContainer ¶
func (container *Container) UpdateContainer(hostConfig *containertypes.HostConfig) error
UpdateContainer updates configuration of a container.
func (*Container) UpdateJoinInfo ¶
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) UpdateMonitor ¶
func (container *Container) UpdateMonitor(restartPolicy containertypes.RestartPolicy)
UpdateMonitor updates monitor configure for running container
func (*Container) UpdateSandboxNetworkSettings ¶
func (container *Container) UpdateSandboxNetworkSettings(sb libnetwork.Sandbox) error
UpdateSandboxNetworkSettings updates the sandbox ID and Key.
func (*Container) WriteHostConfig ¶
WriteHostConfig saves the host configuration on disk for the container.
type DetachError ¶
type DetachError struct{}
DetachError is special error which returned in case of container detach.
func (DetachError) Error ¶
func (DetachError) Error() string
type ExitStatus ¶
type ExitStatus struct { // The exit code with which the container exited. ExitCode int // Whether the container encountered an OOM. OOMKilled bool }
ExitStatus provides exit reasons for a container.
type Health ¶
Health holds the current container health-check state
func (*Health) CloseMonitorChannel ¶
func (s *Health) CloseMonitorChannel()
CloseMonitorChannel closes any existing monitor channel.
func (*Health) OpenMonitorChannel ¶
func (s *Health) OpenMonitorChannel() chan struct{}
OpenMonitorChannel creates and returns a new monitor channel. If there already is one, it returns nil.
type History ¶
type History []*Container
History is a convenience type for storing a list of containers, sorted by creation date in descendant order.
type Mount ¶
type Mount struct { Source string `json:"source"` Destination string `json:"destination"` Writable bool `json:"writable"` Data string `json:"data"` Propagation string `json:"mountpropagation"` }
Mount contains information for a mount operation.
type State ¶
type State struct { sync.Mutex // 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 ExitCodeValue int `json:"ExitCode"` ErrorMsg string `json:"Error"` // contains last known error when starting the container StartedAt time.Time FinishedAt time.Time Health *Health // 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 ¶
func NewState() *State
NewState creates a default state object with a fresh channel for state changes.
func (*State) ExitCode ¶
ExitCode returns current exitcode for the state. Take lock before if state may be shared.
func (*State) HealthString ¶
HealthString returns a single string to describe health status.
func (*State) IsRestarting ¶
IsRestarting returns whether the container is restarting or not.
func (*State) IsRunning ¶
IsRunning returns whether the running flag is set. Used by Container to check whether a container is running.
func (*State) ResetRemovalInProgress ¶
func (s *State) ResetRemovalInProgress()
ResetRemovalInProgress makes the RemovalInProgress state to false.
func (*State) SetError ¶
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) SetExitCode ¶
SetExitCode sets current exitcode for the state. Take lock before if state may be shared.
func (*State) SetRemovalInProgress ¶
SetRemovalInProgress sets the container state as being removed. It returns true if the container was already in that state.
func (*State) SetRestarting ¶
func (s *State) SetRestarting(exitStatus *ExitStatus)
SetRestarting sets the container state to "restarting" without locking. It also sets the container PID to 0.
func (*State) SetRunning ¶
SetRunning sets the state of the container to "running".
func (*State) SetStopped ¶
func (s *State) SetStopped(exitStatus *ExitStatus)
SetStopped sets the container state to "stopped" without locking.
func (*State) StateString ¶
StateString returns a single string to describe state
type StateStatus ¶
type StateStatus struct {
// contains filtered or unexported fields
}
StateStatus is used to return an error type implementing both exec.ExitCode and error. This type is needed as State include a sync.Mutex field which make copying it unsafe.
func (*StateStatus) Error ¶
func (ss *StateStatus) Error() string
Error returns current error for the state.
func (*StateStatus) ExitCode ¶
func (ss *StateStatus) ExitCode() int
ExitCode returns current exitcode for the state.
type Store ¶
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. Delete(string) // 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. ApplyAll(StoreReducer) }
Store defines an interface that any container store must implement.
type StoreFilter ¶
StoreFilter defines a function to filter container in the store.
type StoreReducer ¶
type StoreReducer func(*Container)
StoreReducer defines a function to manipulate containers in the store