Categorygithub.com/crisesw/containerd
modulepackage
1.4.0-beta.2
Repository: https://github.com/crisesw/containerd.git
Documentation: pkg.go.dev

# README

containerd banner

GoDoc Build Status Windows Build Status Nightlies FOSSA Status Go Report Card CII Best Practices

containerd is an industry-standard container runtime with an emphasis on simplicity, robustness and portability. It is available as a daemon for Linux and Windows, which can manage the complete container lifecycle of its host system: image transfer and storage, container execution and supervision, low-level storage and network attachments, etc.

containerd is designed to be embedded into a larger system, rather than being used directly by developers or end-users.

architecture

Getting Started

See our documentation on containerd.io:

See how to build containerd from source at BUILDING.

If you are interested in trying out containerd see our example at Getting Started.

Nightly builds

There are nightly builds available for download here. Binaries are generated from master branch every night for Linux and Windows.

Please be aware: nightly builds might have critical bugs, it's not recommended for use in prodution and no support provided.

Runtime Requirements

Runtime requirements for containerd are very minimal. Most interactions with the Linux and Windows container feature sets are handled via runc and/or OS-specific libraries (e.g. hcsshim for Microsoft). The current required version of runc is always listed in RUNC.md.

There are specific features used by containerd core code and snapshotters that will require a minimum kernel version on Linux. With the understood caveat of distro kernel versioning, a reasonable starting point for Linux is a minimum 4.x kernel version.

The overlay filesystem snapshotter, used by default, uses features that were finalized in the 4.x kernel series. If you choose to use btrfs, there may be more flexibility in kernel version (minimum recommended is 3.18), but will require the btrfs kernel module and btrfs tools to be installed on your Linux distribution.

To use Linux checkpoint and restore features, you will need criu installed on your system. See more details in Checkpoint and Restore.

Build requirements for developers are listed in BUILDING.

Features

Client

containerd offers a full client package to help you integrate containerd into your platform.


import (
  "github.com/containerd/containerd"
  "github.com/containerd/containerd/cio"
)


func main() {
	client, err := containerd.New("/run/containerd/containerd.sock")
	defer client.Close()
}

Namespaces

Namespaces allow multiple consumers to use the same containerd without conflicting with each other. It has the benefit of sharing content but still having separation with containers and images.

To set a namespace for requests to the API:

context = context.Background()
// create a context for docker
docker = namespaces.WithNamespace(context, "docker")

containerd, err := client.NewContainer(docker, "id")

To set a default namespace on the client:

client, err := containerd.New(address, containerd.WithDefaultNamespace("docker"))

Distribution

// pull an image
image, err := client.Pull(context, "docker.io/library/redis:latest")

// push an image
err := client.Push(context, "docker.io/library/redis:latest", image.Target())

Containers

In containerd, a container is a metadata object. Resources such as an OCI runtime specification, image, root filesystem, and other metadata can be attached to a container.

redis, err := client.NewContainer(context, "redis-master")
defer redis.Delete(context)

OCI Runtime Specification

containerd fully supports the OCI runtime specification for running containers. We have built in functions to help you generate runtime specifications based on images as well as custom parameters.

You can specify options when creating a container about how to modify the specification.

redis, err := client.NewContainer(context, "redis-master", containerd.WithNewSpec(oci.WithImageConfig(image)))

Root Filesystems

containerd allows you to use overlay or snapshot filesystems with your containers. It comes with builtin support for overlayfs and btrfs.

// pull an image and unpack it into the configured snapshotter
image, err := client.Pull(context, "docker.io/library/redis:latest", containerd.WithPullUnpack)

// allocate a new RW root filesystem for a container based on the image
redis, err := client.NewContainer(context, "redis-master",
	containerd.WithNewSnapshot("redis-rootfs", image),
	containerd.WithNewSpec(oci.WithImageConfig(image)),
)

// use a readonly filesystem with multiple containers
for i := 0; i < 10; i++ {
	id := fmt.Sprintf("id-%s", i)
	container, err := client.NewContainer(ctx, id,
		containerd.WithNewSnapshotView(id, image),
		containerd.WithNewSpec(oci.WithImageConfig(image)),
	)
}

Tasks

Taking a container object and turning it into a runnable process on a system is done by creating a new Task from the container. A task represents the runnable object within containerd.

// create a new task
task, err := redis.NewTask(context, cio.NewCreator(cio.WithStdio))
defer task.Delete(context)

// the task is now running and has a pid that can be use to setup networking
// or other runtime settings outside of containerd
pid := task.Pid()

// start the redis-server process inside the container
err := task.Start(context)

// wait for the task to exit and get the exit status
status, err := task.Wait(context)

Checkpoint and Restore

If you have criu installed on your machine you can checkpoint and restore containers and their tasks. This allow you to clone and/or live migrate containers to other machines.

// checkpoint the task then push it to a registry
checkpoint, err := task.Checkpoint(context)

err := client.Push(context, "myregistry/checkpoints/redis:master", checkpoint)

// on a new machine pull the checkpoint and restore the redis container
checkpoint, err := client.Pull(context, "myregistry/checkpoints/redis:master")

redis, err = client.NewContainer(context, "redis-master", containerd.WithNewSnapshot("redis-rootfs", checkpoint))
defer container.Delete(context)

task, err = redis.NewTask(context, cio.NewCreator(cio.WithStdio), containerd.WithTaskCheckpoint(checkpoint))
defer task.Delete(context)

err := task.Start(context)

Snapshot Plugins

In addition to the built-in Snapshot plugins in containerd, additional external plugins can be configured using GRPC. An external plugin is made available using the configured name and appears as a plugin alongside the built-in ones.

To add an external snapshot plugin, add the plugin to containerd's config file (by default at /etc/containerd/config.toml). The string following proxy_plugin. will be used as the name of the snapshotter and the address should refer to a socket with a GRPC listener serving containerd's Snapshot GRPC API. Remember to restart containerd for any configuration changes to take effect.

[proxy_plugins]
  [proxy_plugins.customsnapshot]
    type = "snapshot"
    address =  "/var/run/mysnapshotter.sock"

See PLUGINS.md for how to create plugins

Releases and API Stability

Please see RELEASES.md for details on versioning and stability of containerd components.

Downloadable 64-bit Intel/AMD binaries of all official releases are available on our releases page, as well as auto-published to the cri-containerd-release storage bucket.

For other architectures and distribution support, you will find that many Linux distributions package their own containerd and provide it across several architectures, such as Canonical's Ubuntu packaging.

Enabling command auto-completion

Starting with containerd 1.4, the urfave client feature for auto-creation of bash and zsh autocompletion data is enabled. To use the autocomplete feature in a bash shell for example, source the autocomplete/ctr file in your .bashrc, or manually like:

$ source ./contrib/autocomplete/ctr

Distribution of ctr autocomplete for bash and zsh

For bash, copy the contrib/autocomplete/ctr script into /etc/bash_completion.d/ and rename it to ctr. The zsh_autocomplete file is also available and can be used similarly for zsh users.

Provide documentation to users to source this file into their shell if you don't place the autocomplete file in a location where it is automatically loaded for the user's shell environment.

Communication

For async communication and long running discussions please use issues and pull requests on the github repo. This will be the best place to discuss design and implementation.

For sync communication we have a community slack with a #containerd channel that everyone is welcome to join and chat about development.

Slack: Catch us in the #containerd and #containerd-dev channels on dockercommunity.slack.com. Click here for an invite to docker community slack.

Security audit

A third party security audit was performed by Cure53 in 4Q2018; the full report is available in our docs/ directory.

Reporting security issues

If you are reporting a security issue, please reach out discreetly at [email protected].

Licenses

The containerd codebase is released under the Apache 2.0 license. The README.md file, and files in the "docs" folder are licensed under the Creative Commons Attribution 4.0 International License. You may obtain a copy of the license, titled CC-BY-4.0, at http://creativecommons.org/licenses/by/4.0/.

Project details

containerd is the primary open source project within the broader containerd GitHub repository. However, all projects within the repo have common maintainership, governance, and contributing guidelines which are stored in a project repository commonly for all containerd projects.

Please find all these core project documents, including the:

information in our containerd/project repository.

Adoption

Interested to see who is using containerd? Are you using containerd in a project? Please add yourself via pull request to our ADOPTERS.md file.

# Packages

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Package defaults provides several common defaults for interacting with containerd.
No description provided by the author
Package errdefs defines the common errors used throughout containerd packages.
No description provided by the author
Package filters defines a syntax and parser that can be used for the filtration of items across the containerd API.
Package gc experiments with providing central gc tooling to ensure deterministic resource removal within containerd.
Package identifiers provides common validation for identifiers and keys across containerd.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Package metadata stores all labels and object specific metadata by namespace.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Package platforms provides a toolkit for normalizing, matching and specifying container platforms.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Functions

CheckRuntime returns true if the current runtime matches the expected runtime.
GetIndexByMediaType returns the index in a manifest for the specified media type.
GetOCIStopSignal retrieves the stop signal specified in the OCI image config.
GetStopSignal retrieves the container stop signal, specified by the well-known containerd label (StopSignalLabel).
New returns a new containerd client that is connected to the containerd instance provided by address.
NewDiffServiceFromClient returns a new diff service which communicates over a GRPC connection.
NewEventServiceFromClient returns a new event service which communicates over a GRPC connection.
NewExitStatus populates an ExitStatus.
NewImage returns a client image object from the metadata image.
NewImageStoreFromClient returns a new image store client.
NewImageWithPlatform returns a client image object from the metadata image.
NewNamespaceStoreFromClient returns a new namespace store.
NewRemoteContainerStore returns the container Store connected with the provided client.
NewWithConn returns a new containerd client that is connected to the containerd instance provided by the connection.
ParseSignal parses a given string into a syscall.Signal the rawSignal can be a string with "SIG" prefix, or a signal number in string format.
WithAllMetadata downloads all manifests and known-configuration files.
WithAllPlatforms is used to import content for all platforms.
WithCheckpointImage includes the container image in the checkpoint.
WithCheckpointImagePath sets image path for checkpoint option.
WithCheckpointName sets the image name for the checkpoint.
WithCheckpointRuntime includes the container runtime info.
WithCheckpointRW includes the rw in the checkpoint.
WithCheckpointTask includes the running task.
WithCheckpointTaskExit causes the task to exit after checkpoint.
WithContainerExtension appends extension data to the container object.
WithContainerLabels adds the provided labels to the container.
WithContainerService sets the container service.
WithContentStore sets the content store.
WithDefaultNamespace sets the default namespace on the client Any operation that does not have a namespace set on the context will be provided the default namespace.
WithDefaultPlatform sets the default platform matcher on the client.
WithDefaultRuntime sets the default runtime on the client.
WithDialOpts allows grpc.DialOptions to be set on the connection.
WithDiffService sets the diff service.
WithDigestRef is used to create digest images for each manifest in the index.
WithEventService sets the event service.
WithGIDOwner allows console I/O to work with the remapped GID in user namespace.
WithImage sets the provided image as the base for the container.
WithImageHandler adds a base handler to be called on dispatch.
WithImageHandlerWrapper wraps the handlers to be called on dispatch.
WithImageName allows setting the image name as the base for the container.
WithImageRefTranslator is used to translate the index reference to an image reference for the image store.
WithImageService sets the image service.
WithImageStopSignal sets a well-known containerd label (StopSignalLabel) on the container for storing the stop signal specified in the OCI image config.
WithImportCompression compresses uncompressed layers on import.
WithIndexName creates a tag pointing to the imported index.
WithInstallLibs installs libs from the image.
WithInstallPath sets the optional install path.
WithInstallReplace will replace existing files.
WithIntrospectionService sets the introspection service.
WithKillAll kills all processes for a task.
WithKillExecID specifies the process ID.
WithLeasesService sets the lease service.
WithManifestUsage is used to get the usage for an image based on what is reported by the manifests rather than what exists in the content store.
WithMaxConcurrentDownloads sets max concurrent download limit.
WithNamespaceService sets the namespace service.
WithNewSnapshot allocates a new snapshot to be used by the container as the root filesystem in read-write mode.
WithNewSnapshotView allocates a new snapshot to be used by the container as the root filesystem in read-only mode.
WithNewSpec generates a new spec for a new container.
WithNoNewKeyring causes tasks not to be created with a new keyring for secret storage.
WithNoPivotRoot instructs the runtime not to you pivot_root.
WithoutRefreshedMetadata will use the current metadata attached to the container object.
WithPlatform allows the caller to specify a platform to retrieve content for.
WithPlatformMatcher specifies the matcher to use for determining which platforms to pull content for.
WithProcessKill will forcefully kill and delete a process.
WithPullLabel sets a label to be associated with a pulled reference.
WithPullLabels associates a set of labels to a pulled reference.
WithPullSnapshotter specifies snapshotter name used for unpacking.
WithPullUnpack is used to unpack an image after pull.
WithRemappedSnapshot creates a new snapshot and remaps the uid/gid for the filesystem to be used by a container with user namespaces.
WithRemappedSnapshotView is similar to WithRemappedSnapshot but rootfs is mounted as read-only.
WithRemapperLabels creates the labels used by any supporting snapshotter to shift the filesystem ownership (user namespace mapping) automatically; currently supported by the fuse-overlayfs snapshotter.
WithResolver specifies the resolver to use.
WithResources sets the provided resources for task updates.
WithRestoreImage restores the image for the container.
WithRestoreImagePath sets image path for create option.
WithRestoreRuntime restores the runtime for the container.
WithRestoreRW restores the rw layer from the checkpoint for the container.
WithRestoreSpec restores the spec from the checkpoint for the container.
WithRootFS allows a task to be created without a snapshot being allocated to its container.
WithRuntime allows a user to specify the runtime name and additional options that should be used to create tasks for the container.
WithSchema1Conversion is used to convert Docker registry schema 1 manifests to oci manifests on pull.
WithServices sets services used by the client.
WithShimCgroup sets the existing cgroup for the shim.
WithSnapshot uses an existing root filesystem for the container.
WithSnapshotCleanup deletes the rootfs snapshot allocated for the container.
WithSnapshotter sets the provided snapshotter for use by the container This option must appear before other snapshotter options to have an effect.
WithSnapshotters sets the snapshotters.
WithSnapshotUsage will check for referenced snapshots from the image objects and include the snapshot size in the total usage.
WithSpec sets the provided spec on the container.
WithStdinCloser closes the stdin of a process.
WithTaskCheckpoint allows a task to be created with live runtime and memory data from a previous checkpoint.
WithTaskService sets the task service.
WithTimeout sets the connection timeout for the client.
WithUIDOwner allows console I/O to work with the remapped UID in user namespace.
WithUnpackOpts is used to add unpack options to the unpacker.
WithUsageManifestLimit sets the limit to the number of manifests which will be walked for usage.

# Constants

Created indicates the process has been created within containerd but the user's defined process has not started.
DefaultSnapshotter will set the default snapshotter for the platform.
Paused indicates that the process is currently paused.
Pausing indicates that the process is currently switching from a running state into a paused state.
Running indicates the process is currently executing.
Stopped indicates that the process has ran and exited.
StopSignalLabel is a well-known containerd label for storing the stop signal specified in the OCI image config.
Unknown indicates that we could not determine the status from the runtime.
UnknownExitStatus is returned when containerd is unable to determine the exit status of a process.

# Variables

ErrCheckpointRWUnsupported is returned if the container runtime does not support checkpoint.
ErrImageNameNotFoundInIndex is returned when the image name is not found in the index.
ErrMediaTypeNotFound returns an error when a media type in the manifest is unknown.
ErrRuntimeNameNotFoundInIndex is returned when the runtime is not found in the index.
ErrSnapshotterNameNotFoundInIndex is returned when the snapshotter is not found in the index.

# Structs

CheckpointTaskInfo allows specific checkpoint information to be set for the task.
Client is the client to interact with containerd and its various services using a uniform interface.
ExitStatus encapsulates a process's exit status.
InfoConfig specifies how container metadata is fetched.
InstallConfig sets the binary install configuration.
IOCloseInfo allows specific io pipes to be closed on a process.
KillInfo contains information on how to process a Kill action.
ProcessInfo provides platform specific process information.
RemoteContext is used to configure object resolutions and transfers with remote content stores and image providers.
No description provided by the author
Status returns process status and exit information.
TaskInfo sets options for task creation.
UnpackConfig provides configuration for the unpack of an image.
UpdateTaskInfo allows updated specific settings to be changed on a task.
Version of containerd.

# Interfaces

Container is a metadata object for container resources and task creation.
DiffService handles the computation and application of diffs.
EventService handles the publish, forward and subscribe of events.
Image describes an image used by containers.
Process represents a system process.
Task is the executable object within containerd.

# Type aliases

CheckpointOpts are options to manage the checkpoint operation.
CheckpointTaskOpts allows the caller to set checkpoint options.
ClientOpt allows callers to set options on the containerd client.
DeleteOpts allows the caller to set options for the deletion of a container.
ImportOpt allows the caller to specify import specific options.
InfoOpts controls how container metadata is fetched and returned.
InstallOpts configures binary installs.
IOCloserOpts allows the caller to set specific pipes as closed on a process.
KillOpts allows options to be set for the killing of a process.
NewContainerOpts allows the caller to set additional options when creating a container.
NewTaskOpts allows the caller to set options on a new task.
ProcessDeleteOpts allows the caller to set options for the deletion of a task.
ProcessStatus returns a human readable status for the Process representing its current status.
RemoteOpt allows the caller to set distribution options for a remote.
RestoreOpts are options to manage the restore operation.
ServicesOpt allows callers to set options on the services.
UnpackOpt provides configuration for unpack.
UpdateContainerOpts allows the caller to set additional options when updating a container.
UpdateTaskOpts allows a caller to update task settings.
UsageOpt is used to configure the usage calculation.