container

package
v2.1.1 Latest Latest
Warning

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

Go to latest
Published: May 12, 2025 License: Apache-2.0 Imports: 108 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Attach

func Attach(ctx context.Context, client *containerd.Client, req string, options types.ContainerAttachOptions) error

Attach attaches stdin, stdout, and stderr to a running container.

func BlkioOCIOpts added in v2.0.4

func BlkioOCIOpts(options types.ContainerCreateOptions) ([]oci.SpecOpts, error)

func Commit

func Commit(ctx context.Context, client *containerd.Client, rawRef string, req string, options types.ContainerCommitOptions) error

Commit will commit a container’s file changes or settings into a new image.

func Cp

func Cp(ctx context.Context, client *containerd.Client, options types.ContainerCpOptions) error

Cp copies files/folders between a running container and the local filesystem.

func Create

Create will create a container.

func Exec

func Exec(ctx context.Context, client *containerd.Client, args []string, options types.ContainerExecOptions) error

Exec will find the right running container to run a new command.

func GenerateLogURI

func GenerateLogURI(dataStore string) (*url.URL, error)

GenerateLogURI generates a log URI for the current container store

func Inspect

func Inspect(ctx context.Context, client *containerd.Client, containers []string, options types.ContainerInspectOptions) ([]any, error)

Inspect prints detailed information for each container in `containers`.

func Kill

func Kill(ctx context.Context, client *containerd.Client, reqs []string, options types.ContainerKillOptions) error

Kill kills a list of containers

func Logs

func Logs(ctx context.Context, client *containerd.Client, container string, options types.ContainerLogsOptions) error

func NewStatusError

func NewStatusError(id string, status containerd.ProcessStatus) error

NewStatusError creates an ErrContainerStatus from container id and status.

func ParseDevice

func ParseDevice(s string) (hostDevPath string, containerPath string, mode string, err error)

ParseDevice parses the give device string into hostDevPath, containerPath and mode(defaults: "rwm").

func Pause

func Pause(ctx context.Context, client *containerd.Client, reqs []string, options types.ContainerPauseOptions) error

Pause pauses all containers specified by `reqs`.

func Prune

func Prune(ctx context.Context, client *containerd.Client, options types.ContainerPruneOptions) error

Prune remove all stopped containers

func Remove

func Remove(ctx context.Context, client *containerd.Client, containers []string, options types.ContainerRemoveOptions) error

Remove removes a list of `containers`.

func RemoveContainer

func RemoveContainer(ctx context.Context, c containerd.Container, globalOptions types.GlobalCommandOptions, force bool, removeAnonVolumes bool, client *containerd.Client) (retErr error)

RemoveContainer removes a container from containerd store. It will first retrieve system objects (namestore, etcetera), then assess whether we should remove the container or not based of "force" and the status of the task. If we are to delete, it then kills and delete the task. If task removal fails, we stop (except if it was just "NotFound"). We then enter the defer cleanup function that will: - remove the network config (windows only) - delete the container - then and ONLY then, on a successful container remove, clean things-up on our side (volume store, etcetera) If you do need to add more cleanup, please do so at the bottom of the defer function

func Rename

func Rename(ctx context.Context, client *containerd.Client, containerID, newContainerName string,
	options types.ContainerRenameOptions) error

Rename change container name to a new name containerID is container name, short ID, or long ID

func Restart

func Restart(ctx context.Context, client *containerd.Client, containers []string, options types.ContainerRestartOptions) error

Restart will restart one or more containers.

func Start

func Start(ctx context.Context, client *containerd.Client, reqs []string, options types.ContainerStartOptions) error

Start starts a list of `containers`. If attach is true, it only starts a single container.

func Stats

func Stats(ctx context.Context, client *containerd.Client, containerIDs []string, options types.ContainerStatsOptions) error

Stats displays a live stream of container(s) resource usage statistics.

func Stop

func Stop(ctx context.Context, client *containerd.Client, reqs []string, opt types.ContainerStopOptions) error

Stop stops a list of containers specified by `reqs`.

func Top

func Top(ctx context.Context, client *containerd.Client, containers []string, opt types.ContainerTopOptions) error

Top performs the equivalent of running `top` inside of container(s)

func Unpause

func Unpause(ctx context.Context, client *containerd.Client, reqs []string, options types.ContainerUnpauseOptions) error

Unpause unpauses all containers specified by `reqs`.

func UpdateContainerRestartPolicyLabel

func UpdateContainerRestartPolicyLabel(ctx context.Context, client *containerd.Client, container containerd.Container, restartFlag string) error

UpdateContainerRestartPolicyLabel updates the restart policy label of the container.

func Wait

func Wait(ctx context.Context, client *containerd.Client, reqs []string, options types.ContainerWaitOptions) error

Wait blocks until all the containers specified by reqs have stopped, then print their exit codes.

func WithSysctls

func WithSysctls(sysctls map[string]string) oci.SpecOpts

WithSysctls sets the provided sysctls onto the spec

func WithUserNSRemapperLabels added in v2.1.0

func WithUserNSRemapperLabels(uidmaps, gidmaps []specs.LinuxIDMapping) snapshots.Opt

func WithoutRunMount

func WithoutRunMount() func(ctx context.Context, client oci.Client, c *containers.Container, s *oci.Spec) error

WithoutRunMount returns a SpecOpts that unmounts the default tmpfs on "/run"

Types

type ContainerTopOKBody

type ContainerTopOKBody struct {

	// Each process running in the container, where each is process
	// is an array of values corresponding to the titles.
	//
	// Required: true
	Processes [][]string `json:"Processes"`

	// The ps column titles
	// Required: true
	Titles []string `json:"Titles"`
}

ContainerTopOKBody is from https://github.com/moby/moby/blob/v20.10.6/api/types/container/container_top.go

ContainerTopOKBody OK response to ContainerTop operation

type ContainerdIDMap added in v2.1.0

type ContainerdIDMap struct {
	UidMap []specs.LinuxIDMapping `json:"UidMap"`
	GidMap []specs.LinuxIDMapping `json:"GidMap"`
}

IDMap contains the mappings of Uids and Gids.

func (*ContainerdIDMap) Marshal added in v2.1.0

func (i *ContainerdIDMap) Marshal() (string, string)

Marshal serializes the IDMap object into two strings: one uidmap list and another one for gidmap list

func (*ContainerdIDMap) RootPair added in v2.1.0

func (i *ContainerdIDMap) RootPair() (User, error)

RootPair returns the ID pair for the root user

func (*ContainerdIDMap) ToHost added in v2.1.0

func (i *ContainerdIDMap) ToHost(pair User) (User, error)

ToHost returns the host user ID pair for the container ID pair.

func (*ContainerdIDMap) Unmarshal added in v2.1.0

func (i *ContainerdIDMap) Unmarshal(uidMap, gidMap string) error

Unmarshal deserialize the passed uidmap and gidmap strings into a IDMap object. Error is returned in case of failure

type ErrContainerStatus

type ErrContainerStatus struct {
	ID     string
	Status containerd.ProcessStatus
}

ErrContainerStatus represents an error that container is in a status unexpected by the caller. E.g., remove a non-stoped/non-created container without force.

func (ErrContainerStatus) Error

func (e ErrContainerStatus) Error() string

type GPUReq

type GPUReq struct {
	Count        int
	DeviceIDs    []string
	Capabilities []string
}

GPUReq is a request for GPUs.

func ParseGPUOptCSV

func ParseGPUOptCSV(value string) (*GPUReq, error)

ParseGPUOptCSV parses a GPU option from CSV.

type IDMap added in v2.1.0

type IDMap struct {
	ContainerID int `json:"container_id"`
	HostID      int `json:"host_id"`
	Size        int `json:"size"`
}

IDMap contains a single entry for user namespace range remapping. An array of IDMap entries represents the structure that will be provided to the Linux kernel for creating a user namespace.

type IdentityMapping added in v2.1.0

type IdentityMapping struct {
	UIDMaps []IDMap `json:"UIDMaps"`
	GIDMaps []IDMap `json:"GIDMaps"`
}

IdentityMapping contains a mappings of UIDs and GIDs. The zero value represents an empty mapping.

func LoadIdentityMapping added in v2.1.0

func LoadIdentityMapping(spec string) (IdentityMapping, error)

LoadIdentityMapping takes a requested identity mapping specification and using the data from /etc/sub{uid,gid} ranges, creates the uid and gid remapping ranges for that user/group pair. The specification can be in the following formats: (format: <name|uid>[:<group|gid>])

type ListItem

type ListItem struct {
	Command   string
	CreatedAt time.Time
	ID        string
	Image     string
	Platform  string // nerdctl extension
	Names     string
	Ports     string
	Status    string
	Runtime   string // nerdctl extension
	Size      string
	Labels    string
	LabelsMap map[string]string `json:"-"`
}

func List

func List(ctx context.Context, client *containerd.Client, options types.ContainerListOptions) ([]ListItem, error)

List prints containers according to `options`.

func (*ListItem) Label

func (x *ListItem) Label(s string) string

type ThrottleDevice added in v2.0.4

type ThrottleDevice struct {
	Path string
	Rate uint64
}

ThrottleDevice is a structure that holds device:rate_per_second pair

func (*ThrottleDevice) String added in v2.0.4

func (t *ThrottleDevice) String() string

type User added in v2.1.0

type User struct {
	Uid uint32
	Gid uint32
}

User is a Uid and Gid pair of a user

type WeightDevice added in v2.0.4

type WeightDevice struct {
	Path   string
	Weight uint16
}

WeightDevice is a structure that holds device:weight pair

func (*WeightDevice) String added in v2.0.4

func (w *WeightDevice) String() string

Jump to

Keyboard shortcuts

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