Documentation ¶
Overview ¶
Libcontainer provides a native Go implementation for creating containers with namespaces, cgroups, capabilities, and filesystem access controls. It allows you to manage the lifecycle of the container performing additional operations after the container is created.
Index ¶
- func Cgroupfs(l *LinuxFactory) error
- func InitArgs(args ...string) func(*LinuxFactory) error
- func InitPath(path string, args ...string) func(*LinuxFactory) error
- func SystemdCgroups(l *LinuxFactory) error
- func TmpfsRoot(l *LinuxFactory) error
- type Console
- type Container
- type CriuOpts
- type CriuPageServerInfo
- type Error
- type ErrorCode
- type Factory
- type LinuxFactory
- type NetworkInterface
- type Process
- type State
- type Stats
- type Status
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Cgroupfs ¶ added in v0.16.0
func Cgroupfs(l *LinuxFactory) error
Cgroupfs is an options func to configure a LinuxFactory to return containers that use the native cgroups filesystem implementation to create and manage cgroups.
func InitArgs ¶ added in v0.16.0
func InitArgs(args ...string) func(*LinuxFactory) error
InitArgs returns an options func to configure a LinuxFactory with the provided init arguments.
func InitPath ¶ added in v0.16.0
func InitPath(path string, args ...string) func(*LinuxFactory) error
InitPath returns an options func to configure a LinuxFactory with the provided absolute path to the init binary and arguements.
func SystemdCgroups ¶ added in v0.16.0
func SystemdCgroups(l *LinuxFactory) error
SystemdCgroups is an options func to configure a LinuxFactory to return containers that use systemd to create and manage cgroups.
func TmpfsRoot ¶ added in v0.16.0
func TmpfsRoot(l *LinuxFactory) error
TmpfsRoot is an option func to mount LinuxFactory.Root to tmpfs.
Types ¶
type Console ¶ added in v0.16.0
type Console interface { io.ReadWriter io.Closer // Path returns the filesystem path to the slave side of the pty. Path() string // Fd returns the fd for the master of the pty. Fd() uintptr }
Console represents a pseudo TTY.
type Container ¶
type Container interface { // Returns the ID of the container ID() string // Returns the current status of the container. // // errors: // ContainerDestroyed - Container no longer exists, // Systemerror - System error. Status() (Status, error) // State returns the current container's state information. // // errors: // Systemerror - System error. State() (*State, error) // Returns the current config of the container. Config() configs.Config // Returns the PIDs inside this container. The PIDs are in the namespace of the calling process. // // errors: // ContainerDestroyed - Container no longer exists, // Systemerror - System error. // // Some of the returned PIDs may no longer refer to processes in the Container, unless // the Container state is PAUSED in which case every PID in the slice is valid. Processes() ([]int, error) // Returns statistics for the container. // // errors: // ContainerDestroyed - Container no longer exists, // Systemerror - System error. Stats() (*Stats, error) // Set cgroup resources of container as configured // // We can use this to change resources when containers are running. // // errors: // Systemerror - System error. Set(config configs.Config) error // Start a process inside the container. Returns error if process fails to // start. You can track process lifecycle with passed Process structure. // // errors: // ContainerDestroyed - Container no longer exists, // ConfigInvalid - config is invalid, // ContainerPaused - Container is paused, // Systemerror - System error. Start(process *Process) (err error) // Checkpoint checkpoints the running container's state to disk using the criu(8) utility. // // errors: // Systemerror - System error. Checkpoint(criuOpts *CriuOpts) error // Restore restores the checkpointed container to a running state using the criu(8) utiity. // // errors: // Systemerror - System error. Restore(process *Process, criuOpts *CriuOpts) error // Destroys the container after killing all running processes. // // Any event registrations are removed before the container is destroyed. // No error is returned if the container is already destroyed. // // errors: // Systemerror - System error. Destroy() error // If the Container state is RUNNING or PAUSING, sets the Container state to PAUSING and pauses // the execution of any user processes. Asynchronously, when the container finished being paused the // state is changed to PAUSED. // If the Container state is PAUSED, do nothing. // // errors: // ContainerDestroyed - Container no longer exists, // Systemerror - System error. Pause() error // If the Container state is PAUSED, resumes the execution of any user processes in the // Container before setting the Container state to RUNNING. // If the Container state is RUNNING, do nothing. // // errors: // ContainerDestroyed - Container no longer exists, // Systemerror - System error. Resume() error // NotifyOOM returns a read-only channel signaling when the container receives an OOM notification. // // errors: // Systemerror - System error. NotifyOOM() (<-chan struct{}, error) }
A libcontainer container object.
Each container is thread-safe within the same process. Since a container can be destroyed by a separate process, any function may return that the container was not found.
type CriuOpts ¶ added in v1.1.1
type CriuOpts struct { ImagesDirectory string // directory for storing image files WorkDirectory string // directory to cd and write logs/pidfiles/stats to LeaveRunning bool // leave container in running state after checkpoint TcpEstablished bool // checkpoint/restore established TCP connections ExternalUnixConnections bool // allow external unix connections ShellJob bool // allow to dump and restore shell jobs PageServer CriuPageServerInfo // allow to dump to criu page server }
type CriuPageServerInfo ¶ added in v1.1.1
type Error ¶
type Error interface { error // Returns a verbose string including the error message // and a representation of the stack trace suitable for // printing. Detail(w io.Writer) error // Returns the error code for this error. Code() ErrorCode }
API Error type.
type ErrorCode ¶
type ErrorCode int
API error code type.
type Factory ¶
type Factory interface { // Creates a new container with the given id and starts the initial process inside it. // id must be a string containing only letters, digits and underscores and must contain // between 1 and 1024 characters, inclusive. // // The id must not already be in use by an existing container. Containers created using // a factory with the same path (and file system) must have distinct ids. // // Returns the new container with a running process. // // errors: // IdInUse - id is already in use by a container // InvalidIdFormat - id has incorrect format // ConfigInvalid - config is invalid // Systemerror - System error // // On error, any partially created container parts are cleaned up (the operation is atomic). Create(id string, config *configs.Config) (Container, error) // Load takes an ID for an existing container and returns the container information // from the state. This presents a read only view of the container. // // errors: // Path does not exist // Container is stopped // System error Load(id string) (Container, error) // StartInitialization is an internal API to libcontainer used during the reexec of the // container. // // Errors: // Pipe connection error // System error StartInitialization() error // Type returns info string about factory type (e.g. lxc, libcontainer...) Type() string }
type LinuxFactory ¶ added in v0.16.0
type LinuxFactory struct { // Root directory for the factory to store state. Root string // InitPath is the absolute path to the init binary. InitPath string // InitArgs are arguments for calling the init responsibilities for spawning // a container. InitArgs []string // CriuPath is the path to the criu binary used for checkpoint and restore of // containers. CriuPath string // Validator provides validation to container configurations. Validator validate.Validator // NewCgroupsManager returns an initialized cgroups manager for a single container. NewCgroupsManager func(config *configs.Cgroup, paths map[string]string) cgroups.Manager }
LinuxFactory implements the default factory interface for linux based systems.
func (*LinuxFactory) Load ¶ added in v0.16.0
func (l *LinuxFactory) Load(id string) (Container, error)
func (*LinuxFactory) StartInitialization ¶ added in v0.16.0
func (l *LinuxFactory) StartInitialization() (err error)
StartInitialization loads a container by opening the pipe fd from the parent to read the configuration and state This is a low level implementation detail of the reexec and should not be consumed externally
func (*LinuxFactory) Type ¶ added in v0.16.0
func (l *LinuxFactory) Type() string
type NetworkInterface ¶ added in v0.16.0
type Process ¶ added in v0.16.0
type Process struct { // The command to be run followed by any arguments. Args []string // Env specifies the environment variables for the process. Env []string // User will set the uid and gid of the executing process running inside the container // local to the container's user and group configuration. User string // Cwd will change the processes current working directory inside the container's rootfs. Cwd string // Stdin is a pointer to a reader which provides the standard input stream. Stdin io.Reader // Stdout is a pointer to a writer which receives the standard output stream. Stdout io.Writer // Stderr is a pointer to a writer which receives the standard error stream. Stderr io.Writer // ExtraFiles specifies additional open files to be inherited by the container ExtraFiles []*os.File // Capabilities specify the capabilities to keep when executing the process inside the container // All capabilities not specified will be dropped from the processes capability mask Capabilities []string // contains filtered or unexported fields }
Process specifies the configuration and IO for a process inside a container.
func (*Process) NewConsole ¶ added in v0.16.0
NewConsole creates new console for process and returns it
type State ¶
type State struct { // ID is the container ID. ID string `json:"id"` // InitProcessPid is the init process id in the parent namespace. InitProcessPid int `json:"init_process_pid"` // InitProcessStartTime is the init process start time. InitProcessStartTime string `json:"init_process_start"` // Path to all the cgroups setup for a container. Key is cgroup subsystem name // with the value as the path. CgroupPaths map[string]string `json:"cgroup_paths"` // NamespacePaths are filepaths to the container's namespaces. Key is the namespace type // with the value as the path. NamespacePaths map[configs.NamespaceType]string `json:"namespace_paths"` // Config is the container's configuration. Config configs.Config `json:"config"` // Container's standard descriptors (std{in,out,err}), needed for checkpoint and restore ExternalDescriptors []string `json:"external_descriptors,omitempty"` }
State represents a running container's state
type Stats ¶ added in v0.16.0
type Stats struct { Interfaces []*NetworkInterface CgroupStats *cgroups.Stats }
type Status ¶ added in v0.16.0
type Status int
The status of a container.
const ( // The container exists and is running. Running Status = iota + 1 // The container exists, it is in the process of being paused. Pausing // The container exists, but all its processes are paused. Paused // The container exists, but its state is saved on disk Checkpointed // The container does not exist. Destroyed )
Source Files ¶
- capabilities_linux.go
- console.go
- console_linux.go
- container.go
- container_linux.go
- container_userns_linux.go
- criu_opts.go
- error.go
- factory.go
- factory_linux.go
- generic_error.go
- init_linux.go
- network_linux.go
- notify_linux.go
- process.go
- process_linux.go
- restored_process.go
- rootfs_linux.go
- setns_init_linux.go
- standard_init_linux.go
- stats.go
- stats_linux.go
Directories ¶
Path | Synopsis |
---|---|
integration is used for integration testing of libcontainer
|
integration is used for integration testing of libcontainer |
Packet netlink provide access to low level Netlink sockets and messages.
|
Packet netlink provide access to low level Netlink sockets and messages. |
Package seccomp provides native seccomp ( https://www.kernel.org/doc/Documentation/prctl/seccomp_filter.txt ) support for go.
|
Package seccomp provides native seccomp ( https://www.kernel.org/doc/Documentation/prctl/seccomp_filter.txt ) support for go. |