lxc

package module
v0.0.0-...-079aead Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2020 License: LGPL-2.1 Imports: 17 Imported by: 0

README

go-lxc

Go Bindings for LXC (Linux Containers)

LXC is the well-known and heavily tested low-level Linux container runtime. It is in active development since 2008 and has proven itself in critical production environments world-wide. Some of its core contributors are the same people that helped to implement various well-known containerization features inside the Linux kernel.

This package implements Go bindings for the LXC C API (liblxc).

Status

Type Service Status
CI (Linux) Travis Build Status
Go documentation Godoc GoDoc
Static analysis GoReport Go Report Card

Requirements

This package requires LXC >= 1.0.0 and its development package and their dependencies to be installed. Additionally, go-lxc requires Golang 1.10 or later to work. Following command should install required dependencies on Ubuntu 18.10:

sudo apt update
sudo apt install git golang gcc make liblxc1 liblxc-dev lxc-utils pkg-config

Installing

To install it, run:

go get gopkg.in/lxc/go-lxc.v2

Trying

To try examples, run:

# cd ~/go/src/gopkg.in/lxc/go-lxc.v2/examples/

# make
==> Running go vet 
==> Building ...
...

# create/create
2018/12/27 22:39:27 Creating container...

# start/start 
2018/12/27 22:39:39 Starting the container...
2018/12/27 22:39:39 Waiting container to startup networking...

# attach/attach 
2018/12/27 22:39:46 AttachShell
root@rubik:/# hostname
rubik
root@rubik:/# exit
exit
2018/12/27 22:39:52 RunCommand
uid=0(root) gid=0(root) groups=0(root)

# stop/stop 
2018/12/27 22:39:54 Stopping the container...

# destroy/destroy 
2018/12/27 22:39:57 Destroying container...

Stability

The package API will remain stable as described in gopkg.in.

Backwards Compatibility

LXC has always focused on strong backwards compatibility. In fact, the API hasn't been broken from release 1.0.0 onwards. Main LXC is currently at version 2.*.*.

Examples

See the examples directory for some.

Bug reports

Bug reports can be filed at: https://github.com/lxc/go-lxc/issues/new

Contributing

Fixes and new features are greatly appreciated. We'd love to see go-lxc improve. To contribute to go-lxc;

  • Fork the repository
  • Modify your fork
  • Ensure your fork passes all tests
  • Send a pull request
    • Bonus points if the pull request includes what you changed, why you changed it, and tests attached.

Getting help

When you find you need help, the LXC projects provides you with several options.

Discuss Forum

We maintain an discuss forum at

where you can get support.

IRC

You can find support by joining #lxcontainers on Freenode.

Mailing Lists

You can check out one of the two LXC mailing list archives and register if interested:

Documentation

Overview

Package lxc provides Go Bindings for LXC (Linux Containers) C API.

LXC (LinuX Containers) is an operating system–level virtualization method for running multiple isolated Linux systems (containers) on a single control host.

LXC combines cgroups and namespace support to provide an isolated environment for applications.

Index

Constants

View Source
const (
	ErrAddDeviceNodeFailed           = lxcError("adding device to container failed")
	ErrAllocationFailed              = lxcError("allocating memory failed")
	ErrAlreadyDefined                = lxcError("container already defined")
	ErrAlreadyFrozen                 = lxcError("container is already frozen")
	ErrAlreadyRunning                = lxcError("container is already running")
	ErrAttachFailed                  = lxcError("attaching to the container failed")
	ErrAttachInterfaceFailed         = lxcError("attaching specified netdev to the container failed")
	ErrBlkioUsage                    = lxcError("BlkioUsage for the container failed")
	ErrCheckpointFailed              = lxcError("checkpoint failed")
	ErrClearingConfigItemFailed      = lxcError("clearing config item for the container failed")
	ErrClearingCgroupItemFailed      = lxcError("clearing cgroup item for the container failed")
	ErrCloneFailed                   = lxcError("cloning the container failed")
	ErrCloseAllFdsFailed             = lxcError("setting close_all_fds flag for container failed")
	ErrCreateFailed                  = lxcError("creating the container failed")
	ErrCreateSnapshotFailed          = lxcError("snapshotting the container failed")
	ErrDaemonizeFailed               = lxcError("setting daemonize flag for container failed")
	ErrDestroyAllSnapshotsFailed     = lxcError("destroying all snapshots failed")
	ErrDestroyFailed                 = lxcError("destroying the container failed")
	ErrDestroySnapshotFailed         = lxcError("destroying the snapshot failed")
	ErrDestroyWithAllSnapshotsFailed = lxcError("destroying the container with all snapshots failed")
	ErrDetachInterfaceFailed         = lxcError("detaching specified netdev to the container failed")
	ErrExecuteFailed                 = lxcError("executing the command in a temporary container failed")
	ErrFreezeFailed                  = lxcError("freezing the container failed")
	ErrInsufficientNumberOfArguments = lxcError("insufficient number of arguments were supplied")
	ErrInterfaces                    = lxcError("getting interface names for the container failed")
	ErrIPAddresses                   = lxcError("getting IP addresses of the container failed")
	ErrIPAddress                     = lxcError("getting IP address on the interface of the container failed")
	ErrIPv4Addresses                 = lxcError("getting IPv4 addresses of the container failed")
	ErrIPv6Addresses                 = lxcError("getting IPv6 addresses of the container failed")
	ErrKMemLimit                     = lxcError("your kernel does not support cgroup kernel memory controller")
	ErrLoadConfigFailed              = lxcError("loading config file for the container failed")
	ErrMemLimit                      = lxcError("your kernel does not support cgroup memory controller")
	ErrMemorySwapLimit               = lxcError("your kernel does not support cgroup swap controller")
	ErrMethodNotAllowed              = lxcError("the requested method is not currently supported with unprivileged containers")
	ErrNewFailed                     = lxcError("allocating the container failed")
	ErrNoSnapshot                    = lxcError("container has no snapshot")
	ErrNotDefined                    = lxcError("container is not defined")
	ErrNotFrozen                     = lxcError("container is not frozen")
	ErrNotRunning                    = lxcError("container is not running")
	ErrNotSupported                  = lxcError("method is not supported by this LXC version")
	ErrRebootFailed                  = lxcError("rebooting the container failed")
	ErrRemoveDeviceNodeFailed        = lxcError("removing device from container failed")
	ErrRenameFailed                  = lxcError("renaming the container failed")
	ErrRestoreFailed                 = lxcError("restore failed")
	ErrRestoreSnapshotFailed         = lxcError("restoring the container failed")
	ErrSaveConfigFailed              = lxcError("saving config file for the container failed")
	ErrSettingCgroupItemFailed       = lxcError("setting cgroup item for the container failed")
	ErrSettingConfigItemFailed       = lxcError("setting config item for the container failed")
	ErrSettingConfigPathFailed       = lxcError("setting config file for the container failed")
	ErrSettingKMemoryLimitFailed     = lxcError("setting kernel memory limit for the container failed")
	ErrSettingMemoryLimitFailed      = lxcError("setting memory limit for the container failed")
	ErrSettingMemorySwapLimitFailed  = lxcError("setting memory+swap limit for the container failed")
	ErrSettingSoftMemoryLimitFailed  = lxcError("setting soft memory limit for the container failed")
	ErrShutdownFailed                = lxcError("shutting down the container failed")
	ErrSoftMemLimit                  = lxcError("your kernel does not support cgroup memory controller")
	ErrStartFailed                   = lxcError("starting the container failed")
	ErrStopFailed                    = lxcError("stopping the container failed")
	ErrTemplateNotAllowed            = lxcError("unprivileged users only allowed to use \"download\" template")
	ErrUnfreezeFailed                = lxcError("unfreezing the container failed")
	ErrUnknownBackendStore           = lxcError("unknown backend type")
	ErrReleaseFailed                 = lxcError("releasing the container failed")
)
View Source
const (
	MIGRATE_PRE_DUMP      = 0
	MIGRATE_DUMP          = 1
	MIGRATE_RESTORE       = 2
	MIGRATE_FEATURE_CHECK = 3
)

Variables

View Source
var BusyboxTemplateOptions = TemplateOptions{
	Template: "busybox",
}

BusyboxTemplateOptions is a convenient set of options for "busybox" template.

View Source
var DefaultAttachOptions = AttachOptions{
	Namespaces: -1,
	Arch:       -1,
	Cwd:        "/",
	UID:        -1,
	GID:        -1,
	Groups:     nil,
	ClearEnv:   false,
	Env:        nil,
	EnvToKeep:  nil,
	StdinFd:    os.Stdin.Fd(),
	StdoutFd:   os.Stdout.Fd(),
	StderrFd:   os.Stderr.Fd(),
}

DefaultAttachOptions is a convenient set of options to be used.

View Source
var DefaultCloneOptions = CloneOptions{
	Backend: Directory,
}

DefaultCloneOptions is a convenient set of options to be used.

View Source
var DefaultConsoleOptions = ConsoleOptions{
	Tty:             -1,
	StdinFd:         os.Stdin.Fd(),
	StdoutFd:        os.Stdout.Fd(),
	StderrFd:        os.Stderr.Fd(),
	EscapeCharacter: 'a',
}

DefaultConsoleOptions is a convenient set of options to be used.

View Source
var DownloadTemplateOptions = TemplateOptions{
	Template: "download",
	Distro:   "ubuntu",
	Release:  "trusty",
	Arch:     "amd64",
}

DownloadTemplateOptions is a convenient set of options for "download" template.

View Source
var StateMap = map[string]State{
	"STOPPED":  STOPPED,
	"STARTING": STARTING,
	"RUNNING":  RUNNING,
	"STOPPING": STOPPING,
	"ABORTING": ABORTING,
	"FREEZING": FREEZING,
	"FROZEN":   FROZEN,
	"THAWED":   THAWED,
}

StateMap provides the mapping betweens the state names and states

View Source
var UbuntuTemplateOptions = TemplateOptions{
	Template: "ubuntu",
}

UbuntuTemplateOptions is a convenient set of options for "ubuntu" template.

Functions

func Acquire

func Acquire(c *Container) bool

Acquire increments the reference counter of the container object.

func ActiveContainerNames

func ActiveContainerNames(lxcpath ...string) []string

ActiveContainerNames returns the names of the active containers on the system.

func ContainerNames

func ContainerNames(lxcpath ...string) []string

ContainerNames returns the names of defined and active containers on the system.

func DefaultConfigPath

func DefaultConfigPath() string

DefaultConfigPath returns default config path.

func DefaultLvmVg

func DefaultLvmVg() string

DefaultLvmVg returns the name of the default LVM volume group.

func DefaultZfsRoot

func DefaultZfsRoot() string

DefaultZfsRoot returns the name of the default ZFS root.

func DefinedContainerNames

func DefinedContainerNames(lxcpath ...string) []string

DefinedContainerNames returns the names of the defined containers on the system.

func GlobalConfigItem

func GlobalConfigItem(name string) string

GlobalConfigItem returns the value of the given global config key.

func HasApiExtension

func HasApiExtension(extension string) bool

HasApiExtension returns true if the extension is supported.

func IsSupportedConfigItem

func IsSupportedConfigItem(key string) bool

IsSupportedConfigItem returns true if the key belongs to a supported config item.

func Release

func Release(c *Container) bool

Release decrements the reference counter of the container object.

func Version

func Version() string

Version returns the LXC version.

func VersionAtLeast

func VersionAtLeast(major int, minor int, micro int) bool

VersionAtLeast returns true when the tested version >= current version.

func VersionNumber

func VersionNumber() (major int, minor int)

VersionNumber returns the LXC version.

Types

type AttachOptions

type AttachOptions struct {

	// Specify the namespaces to attach to, as OR'ed list of clone flags (syscall.CLONE_NEWNS | syscall.CLONE_NEWUTS ...).
	Namespaces int

	// Specify the architecture which the kernel should appear to be running as to the command executed.
	Arch Personality

	// Cwd specifies the working directory of the command.
	Cwd string

	// UID specifies the user id to run as.
	UID int

	// GID specifies the group id to run as.
	GID int

	// Groups specifies the list of additional group ids to run with.
	Groups []int

	// If ClearEnv is true the environment is cleared before running the command.
	ClearEnv bool

	// Env specifies the environment of the process.
	Env []string

	// EnvToKeep specifies the environment of the process when ClearEnv is true.
	EnvToKeep []string

	// StdinFd specifies the fd to read input from.
	StdinFd uintptr

	// StdoutFd specifies the fd to write output to.
	StdoutFd uintptr

	// StderrFd specifies the fd to write error output to.
	StderrFd uintptr
}

AttachOptions type is used for defining various attach options.

type BackendStore

type BackendStore int

BackendStore type specifies possible backend types.

const (
	// Btrfs backendstore type
	Btrfs BackendStore = iota + 1
	// Directory backendstore type
	Directory
	// LVM backendstore type
	LVM
	// ZFS backendstore type
	ZFS
	// Aufs backendstore type
	Aufs
	// Overlayfs backendstore type
	Overlayfs
	// Loopback backendstore type
	Loopback
	// Best backendstore type
	Best
)

func (*BackendStore) Set

func (t *BackendStore) Set(value string) error

Set is the method to set the flag value, part of the flag.Value interface.

func (BackendStore) String

func (t BackendStore) String() string

BackendStore as string

type BackendStoreSpecs

type BackendStoreSpecs struct {
	FSType string
	FSSize uint64
	Dir    *string
	ZFS    struct {
		Root string
	}
	LVM struct {
		VG, LV, Thinpool string
	}
	RBD struct {
		Name, Pool string
	}
}

type ByteSize

type ByteSize float64

ByteSize type

const (
	B = iota
	// KB - kilobyte
	KB ByteSize = 1 << (10 * iota)
	// MB - megabyte
	MB
	// GB - gigabyte
	GB
	// TB - terabyte
	TB
	// PB - petabyte
	PB
	// EB - exabyte
	EB
	// ZB - zettabyte
	ZB
	// YB - yottabyte
	YB
)

func ParseBytes

func ParseBytes(s string) (ByteSize, error)

ParseBytes parses a byte size string. A byte size string is a number followed by a unit suffix, such as "1024B" or "1 MB". Valid byte units are "B", "KB", "MB", "GB", "TB", "PB" and "EB". You can also use the long format of units, such as "kilobyte" or "kilobytes".

func (ByteSize) String

func (b ByteSize) String() string

type CheckpointOptions

type CheckpointOptions struct {
	Directory string
	Stop      bool
	Verbose   bool
}

CheckpointOptions type is used for defining checkpoint options for CRIU.

type CloneOptions

type CloneOptions struct {

	// Backend specifies the type of the backend.
	Backend BackendStore

	// lxcpath in which to create the new container. If not set the original container's lxcpath will be used.
	ConfigPath string

	// Do not change the hostname of the container (in the root filesystem).
	KeepName bool

	// Use the same MAC address as the original container, rather than generating a new random one.
	KeepMAC bool

	// Create a snapshot rather than copy.
	Snapshot bool
}

CloneOptions type is used for defining various clone options.

type ConsoleLogOptions

type ConsoleLogOptions struct {
	ClearLog       bool
	ReadLog        bool
	ReadMax        uint64
	WriteToLogFile bool
}

ConsoleLogOptions type is used for defining console log options.

type ConsoleOptions

type ConsoleOptions struct {

	// Tty number to attempt to allocate, -1 to allocate the first available tty, or 0 to allocate the console.
	Tty int

	// StdinFd specifies the fd to read input from.
	StdinFd uintptr

	// StdoutFd specifies the fd to write output to.
	StdoutFd uintptr

	// StderrFd specifies the fd to write error output to.
	StderrFd uintptr

	// EscapeCharacter (a means <Ctrl a>, b maens <Ctrl b>).
	EscapeCharacter rune
}

ConsoleOptions type is used for defining various console options.

type Container

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

Container struct

func ActiveContainers

func ActiveContainers(lxcpath ...string) []*Container

ActiveContainers returns the active containers on the system. Only containers that could retrieved successfully are returned. Caller needs to call Release() on the returned containers to release resources.

func Containers

func Containers(lxcpath ...string) []*Container

Containers returns the defined and active containers on the system. Only containers that could retrieved successfully are returned. Caller needs to call Release() on the returned containers to release resources.

func DefinedContainers

func DefinedContainers(lxcpath ...string) []*Container

DefinedContainers returns the defined containers on the system. Only containers that could retrieved successfully are returned. Caller needs to call Release() on the returned containers to release resources.

func NewContainer

func NewContainer(name string, lxcpath ...string) (*Container, error)

NewContainer returns a new container struct. Caller needs to call Release() on the returned container to release its resources.

func (*Container) AddDeviceNode

func (c *Container) AddDeviceNode(source string, destination ...string) error

AddDeviceNode adds specified device to the container.

func (*Container) AttachInterface

func (c *Container) AttachInterface(source, destination string) error

AttachInterface attaches specified netdev to the container.

func (*Container) AttachShell

func (c *Container) AttachShell(options AttachOptions) error

AttachShell attaches a shell to the container. It clears all environment variables before attaching.

func (*Container) BlkioUsage

func (c *Container) BlkioUsage() (ByteSize, error)

BlkioUsage returns number of bytes transferred to/from the disk by the container.

func (*Container) CPUStats

func (c *Container) CPUStats() (map[string]int64, error)

CPUStats returns the number of CPU cycles (in the units defined by USER_HZ on the system) consumed by tasks in this cgroup and its children in both user mode and system (kernel) mode.

func (*Container) CPUTime

func (c *Container) CPUTime() (time.Duration, error)

CPUTime returns the total CPU time (in nanoseconds) consumed by all tasks in this cgroup (including tasks lower in the hierarchy).

func (*Container) CPUTimePerCPU

func (c *Container) CPUTimePerCPU() (map[int]time.Duration, error)

CPUTimePerCPU returns the CPU time (in nanoseconds) consumed on each CPU by all tasks in this cgroup (including tasks lower in the hierarchy).

func (*Container) CgroupItem

func (c *Container) CgroupItem(key string) []string

CgroupItem returns the value of the given cgroup subsystem value.

func (*Container) Checkpoint

func (c *Container) Checkpoint(opts CheckpointOptions) error

Checkpoint checkpoints the container.

func (*Container) ClearConfig

func (c *Container) ClearConfig()

ClearConfig completely clears the containers in-memory configuration.

func (*Container) ClearConfigItem

func (c *Container) ClearConfigItem(key string) error

ClearConfigItem clears the value of given config item.

func (*Container) Clone

func (c *Container) Clone(name string, options CloneOptions) error

Clone clones the container using given arguments with specified backend.

func (*Container) ConfigFileName

func (c *Container) ConfigFileName() string

ConfigFileName returns the container's configuration file's name.

func (*Container) ConfigItem

func (c *Container) ConfigItem(key string) []string

ConfigItem returns the value of the given config item.

func (*Container) ConfigKeys

func (c *Container) ConfigKeys(key ...string) []string

ConfigKeys returns the names of the config items.

func (*Container) ConfigPath

func (c *Container) ConfigPath() string

ConfigPath returns the configuration file's path.

func (*Container) Console

func (c *Container) Console(options ConsoleOptions) error

Console allocates and runs a console tty from container

This function will not return until the console has been exited by the user.

func (*Container) ConsoleFd

func (c *Container) ConsoleFd(ttynum int) (int, error)

ConsoleFd allocates a console tty from container ttynum: tty number to attempt to allocate or -1 to allocate the first available tty

Returns "ttyfd" on success, -1 on failure. The returned "ttyfd" is used to keep the tty allocated. The caller should close "ttyfd" to indicate that it is done with the allocated console so that it can be allocated by another caller.

func (*Container) ConsoleLog

func (c *Container) ConsoleLog(opt ConsoleLogOptions) ([]byte, error)

ConsoleLog allows to perform operations on the container's in-memory console buffer.

func (*Container) Controllable

func (c *Container) Controllable() bool

Controllable returns true if the caller can control the container.

func (*Container) Create

func (c *Container) Create(options TemplateOptions) error

Create creates the container using given TemplateOptions

func (*Container) CreateSnapshot

func (c *Container) CreateSnapshot() (*Snapshot, error)

CreateSnapshot creates a new snapshot.

func (*Container) Daemonize

func (c *Container) Daemonize() bool

Daemonize returns true if the container wished to be daemonized.

func (*Container) Defined

func (c *Container) Defined() bool

Defined returns true if the container is already defined.

func (*Container) Destroy

func (c *Container) Destroy() error

Destroy destroys the container.

func (*Container) DestroyAllSnapshots

func (c *Container) DestroyAllSnapshots() error

DestroyAllSnapshots destroys all the snapshot.

func (*Container) DestroySnapshot

func (c *Container) DestroySnapshot(snapshot Snapshot) error

DestroySnapshot destroys the specified snapshot.

func (*Container) DestroyWithAllSnapshots

func (c *Container) DestroyWithAllSnapshots() error

DestroyWithAllSnapshots destroys the container and its snapshots

func (*Container) DetachInterface

func (c *Container) DetachInterface(source string) error

DetachInterface detaches specified netdev from the container.

func (*Container) DetachInterfaceRename

func (c *Container) DetachInterfaceRename(source, target string) error

DetachInterfaceRename detaches specified netdev from the container and renames it.

func (*Container) DevptsFd

func (c *Container) DevptsFd() (*os.File, error)

DevptsFd returns the pidfd of the container's init process.

func (*Container) ErrorNum

func (c *Container) ErrorNum() int

ErrorNum returns the error_num field of the container.

func (*Container) Execute

func (c *Container) Execute(args ...string) ([]byte, error)

Execute executes the given command in a temporary container.

func (*Container) Freeze

func (c *Container) Freeze() error

Freeze freezes the running container.

func (*Container) IPAddress

func (c *Container) IPAddress(interfaceName string) ([]string, error)

IPAddress returns the IP address of the given network interface.

func (*Container) IPAddresses

func (c *Container) IPAddresses() ([]string, error)

IPAddresses returns all IP addresses.

func (*Container) IPv4Address

func (c *Container) IPv4Address(interfaceName string) ([]string, error)

IPv4Address returns the IPv4 address of the given network interface.

func (*Container) IPv4Addresses

func (c *Container) IPv4Addresses() ([]string, error)

IPv4Addresses returns all IPv4 addresses.

func (*Container) IPv6Address

func (c *Container) IPv6Address(interfaceName string) ([]string, error)

IPv6Address returns the IPv6 address of the given network interface.

func (*Container) IPv6Addresses

func (c *Container) IPv6Addresses() ([]string, error)

IPv6Addresses returns all IPv6 addresses.

func (*Container) InitPid

func (c *Container) InitPid() int

InitPid returns the process ID of the container's init process seen from outside the container.

func (*Container) InitPidFd

func (c *Container) InitPidFd() (*os.File, error)

InitPidFd returns the pidfd of the container's init process.

func (*Container) InterfaceStats

func (c *Container) InterfaceStats() (map[string]map[string]ByteSize, error)

InterfaceStats returns the stats about container's network interfaces

func (*Container) Interfaces

func (c *Container) Interfaces() ([]string, error)

Interfaces returns the names of the network interfaces.

func (*Container) KernelMemoryLimit

func (c *Container) KernelMemoryLimit() (ByteSize, error)

KernelMemoryLimit returns kernel memory limit of the container in bytes.

func (*Container) KernelMemoryUsage

func (c *Container) KernelMemoryUsage() (ByteSize, error)

KernelMemoryUsage returns current kernel memory allocation of the container in bytes.

func (*Container) LoadConfigFile

func (c *Container) LoadConfigFile(path string) error

LoadConfigFile loads the configuration file from given path.

func (*Container) LogFile

func (c *Container) LogFile() string

LogFile returns the name of the logfile.

func (*Container) LogLevel

func (c *Container) LogLevel() LogLevel

LogLevel returns the level of the logfile.

func (*Container) MemoryLimit

func (c *Container) MemoryLimit() (ByteSize, error)

MemoryLimit returns memory limit of the container in bytes.

func (*Container) MemorySwapLimit

func (c *Container) MemorySwapLimit() (ByteSize, error)

MemorySwapLimit returns the memory+swap limit of the container in bytes.

func (*Container) MemorySwapUsage

func (c *Container) MemorySwapUsage() (ByteSize, error)

MemorySwapUsage returns memory+swap usage of the container in bytes.

func (*Container) MemoryUsage

func (c *Container) MemoryUsage() (ByteSize, error)

MemoryUsage returns memory usage of the container in bytes.

func (*Container) Migrate

func (c *Container) Migrate(cmd uint, opts MigrateOptions) error

Migrate migrates the container.

func (*Container) Name

func (c *Container) Name() string

Name returns the name of the container.

func (*Container) Reboot

func (c *Container) Reboot() error

Reboot reboots the container.

func (*Container) Release

func (c *Container) Release() error

Release decrements the reference counter of the container object. nil on success or if reference was successfully dropped and container has been freed, and ErrReleaseFailed on error.

func (*Container) RemoveDeviceNode

func (c *Container) RemoveDeviceNode(source string, destination ...string) error

RemoveDeviceNode removes the specified device from the container.

func (*Container) Rename

func (c *Container) Rename(name string) error

Rename renames the container.

func (*Container) Restore

func (c *Container) Restore(opts RestoreOptions) error

Restore restores the container from a checkpoint.

func (*Container) RestoreSnapshot

func (c *Container) RestoreSnapshot(snapshot Snapshot, name string) error

RestoreSnapshot creates a new container based on a snapshot.

func (*Container) RunCommand

func (c *Container) RunCommand(args []string, options AttachOptions) (bool, error)

RunCommand attachs a shell and runs the command within the container. The process will wait for the command to finish and return a success status. An error is returned only when invocation of the command completely fails.

func (*Container) RunCommandNoWait

func (c *Container) RunCommandNoWait(args []string, options AttachOptions) (int, error)

RunCommandNoWait runs the given command and returns without waiting it to finish.

func (*Container) RunCommandStatus

func (c *Container) RunCommandStatus(args []string, options AttachOptions) (int, error)

RunCommandStatus attachs a shell and runs the command within the container. The process will wait for the command to finish and return the result of waitpid(), i.e. the process' exit status. An error is returned only when invocation of the command completely fails.

func (*Container) Running

func (c *Container) Running() bool

Running returns true if the container is already running.

func (*Container) RunningConfigItem

func (c *Container) RunningConfigItem(key string) []string

RunningConfigItem returns the value of the given config item.

func (*Container) SaveConfigFile

func (c *Container) SaveConfigFile(path string) error

SaveConfigFile saves the configuration file to given path.

func (*Container) SeccompNotifyFd

func (c *Container) SeccompNotifyFd() (*os.File, error)

SeccompNotifyFd returns the seccomp notify fd of the container.

func (*Container) SeccompNotifyFdActive

func (c *Container) SeccompNotifyFdActive() (*os.File, error)

SeccompNotifyFdActive returns the seccomp notify fd of the running container.

func (*Container) SetCgroupItem

func (c *Container) SetCgroupItem(key string, value string) error

SetCgroupItem sets the value of given cgroup subsystem value.

func (*Container) SetConfigItem

func (c *Container) SetConfigItem(key string, value string) error

SetConfigItem sets the value of the given config item.

func (*Container) SetConfigPath

func (c *Container) SetConfigPath(path string) error

SetConfigPath sets the configuration file's path.

func (*Container) SetKernelMemoryLimit

func (c *Container) SetKernelMemoryLimit(limit ByteSize) error

SetKernelMemoryLimit sets kernel memory limit of the container in bytes.

func (*Container) SetLogFile

func (c *Container) SetLogFile(filename string) error

SetLogFile sets the name of the logfile.

func (*Container) SetLogLevel

func (c *Container) SetLogLevel(level LogLevel) error

SetLogLevel sets the level of the logfile.

func (*Container) SetMemoryLimit

func (c *Container) SetMemoryLimit(limit ByteSize) error

SetMemoryLimit sets memory limit of the container in bytes.

func (*Container) SetMemorySwapLimit

func (c *Container) SetMemorySwapLimit(limit ByteSize) error

SetMemorySwapLimit sets memory+swap limit of the container in bytes.

func (*Container) SetSoftMemoryLimit

func (c *Container) SetSoftMemoryLimit(limit ByteSize) error

SetSoftMemoryLimit sets soft memory limit of the container in bytes.

func (*Container) SetVerbosity

func (c *Container) SetVerbosity(verbosity Verbosity)

SetVerbosity sets the verbosity level of some API calls

func (*Container) Shutdown

func (c *Container) Shutdown(timeout time.Duration) error

Shutdown shuts down the container.

func (*Container) Snapshots

func (c *Container) Snapshots() ([]Snapshot, error)

Snapshots returns the list of container snapshots.

func (*Container) SoftMemoryLimit

func (c *Container) SoftMemoryLimit() (ByteSize, error)

SoftMemoryLimit returns soft memory limit of the container in bytes.

func (*Container) Start

func (c *Container) Start() error

Start starts the container.

func (*Container) StartExecute

func (c *Container) StartExecute(args []string) error

StartExecute starts a container. It runs a minimal init as PID 1 and the requested program as the second process.

func (*Container) StartWithArgs

func (c *Container) StartWithArgs(args []string) error

StartWithArgs starts the container using given arguments.

func (*Container) State

func (c *Container) State() State

State returns the state of the container.

func (*Container) Stop

func (c *Container) Stop() error

Stop stops the container.

func (*Container) String

func (c *Container) String() string

String returns the string representation of container.

func (*Container) Unfreeze

func (c *Container) Unfreeze() error

Unfreeze thaws the frozen container.

func (*Container) Wait

func (c *Container) Wait(state State, timeout time.Duration) bool

Wait waits for container to reach a particular state.

func (*Container) WaitIPAddresses

func (c *Container) WaitIPAddresses(timeout time.Duration) ([]string, error)

WaitIPAddresses waits until IPAddresses call returns something or time outs

func (*Container) WantCloseAllFds

func (c *Container) WantCloseAllFds(state bool) error

WantCloseAllFds determines whether container wishes all file descriptors to be closed on startup.

func (*Container) WantDaemonize

func (c *Container) WantDaemonize(state bool) error

WantDaemonize determines if the container wants to run daemonized.

type CriuFeatures

type CriuFeatures uint64
const (
	FEATURE_MEM_TRACK CriuFeatures = 1 << iota
	FEATURE_LAZY_PAGES
)

type LogLevel

type LogLevel int

LogLevel type specifies possible log levels.

const (
	// TRACE priority
	TRACE LogLevel = iota
	// DEBUG priority
	DEBUG
	// INFO priority
	INFO
	// NOTICE priority
	NOTICE
	// WARN priority
	WARN
	// ERROR priority
	ERROR
	// CRIT priority
	CRIT
	// ALERT priority
	ALERT
	// FATAL priority
	FATAL
)

func (LogLevel) String

func (l LogLevel) String() string

type MigrateOptions

type MigrateOptions struct {
	Directory       string
	PredumpDir      string
	ActionScript    string
	Verbose         bool
	Stop            bool
	PreservesInodes bool
	GhostLimit      uint64
	FeaturesToCheck CriuFeatures
}

MigrateOptions type is used for defining migrate options.

type Personality

type Personality int64

Personality allows to set the architecture for the container.

const (
	X86    Personality = 0x0008
	X86_64             = 0x0000
)

type RestoreOptions

type RestoreOptions struct {
	Directory string
	Verbose   bool
}

RestoreOptions type is used for defining restore options for CRIU.

type Snapshot

type Snapshot struct {
	Name        string
	CommentPath string
	Timestamp   string
	Path        string
}

Snapshot struct

type State

type State int

State type specifies possible container states.

const (
	// STOPPED means container is not running
	STOPPED State = iota + 1
	// STARTING means container is starting
	STARTING
	// RUNNING means container is running
	RUNNING
	// STOPPING means container is stopping
	STOPPING
	// ABORTING means container is aborting
	ABORTING
	// FREEZING means container is freezing
	FREEZING
	// FROZEN means containe is frozen
	FROZEN
	// THAWED means container is thawed
	THAWED
)

func (State) String

func (t State) String() string

State as string

type TemplateOptions

type TemplateOptions struct {

	// Template specifies the name of the template.
	Template string

	// Backend specifies the type of the backend.
	Backend BackendStore

	BackendSpecs *BackendStoreSpecs

	// Distro specifies the name of the distribution.
	Distro string

	// Release specifies the name/version of the distribution.
	Release string

	// Arch specified the architecture of the container.
	Arch string

	// Variant specifies the variant of the image (default: "default").
	Variant string

	// Image server (default: "images.linuxcontainers.org").
	Server string

	// GPG keyid (default: 0x...).
	KeyID string

	// GPG keyserver to use.
	KeyServer string

	// Disable GPG validation (not recommended).
	DisableGPGValidation bool

	// Flush the local copy (if present).
	FlushCache bool

	// Force the use of the local copy even if expired.
	ForceCache bool

	// ExtraArgs provides a way to specify template specific args.
	ExtraArgs []string
}

TemplateOptions type is used for defining various template options.

type Verbosity

type Verbosity int

Verbosity type

const (
	// Quiet makes some API calls not to write anything to stdout
	Quiet Verbosity = 1 << iota
	// Verbose makes some API calls write to stdout
	Verbose
)

Jump to

Keyboard shortcuts

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