高性能容器伺服器-containerd簡介

containerd是一個高性能的容器(container)伺服系統(查看源碼),部分功能與Docker很像,至關於Docker Daemon模式和更新版的DockerD。git

  • containerd採用並行啓動技術,能夠每秒啓動上百個容器實例。containerd提供命令行和REST服務接口,裏面對容器真正的管理是經過containerd-shim進程來完成
  • 與Docker Engine的一鍋燴模式不一樣的是,containerd並無論理容器的鏡像,主要支持OCI(https://www.opencontainers.org/)開放容器標準的鏡像,經過runc來啓動。
  • OCI鏡像能夠經過Docker鏡像轉換而來(參見:https://github.com/docker/containerd/blob/master/docs/bundle.md)。

containerd與你們熟知的Docker可謂相生相剋,最新發展出的關係以下圖所示。github

  • Docker從1.11開始,已經支持containerd和runc來運行容器。在DockerD服務啓動時自動啓動了containerd做爲後臺進程服務(能夠經過ps aux | grep docker查看)。
  • 更詳細的中文介紹參考:http://dockone.io/article/1327 。

 

下面是containerd的官方介紹,原文:https://containerd.tools/redis

About containerd

Containerd is a daemon with an API and a command line client, to manage containers on one machine. It uses runC to run containers according to the OCI specification. Containerd has advanced features such as seccomp and user namespace support as well as checkpoint and restore for cloning and live migration of containers. The code can be found on Github. Containerd is currently available as an alpha release.docker

Built for Performance

Starting 1000 containers concurrently runs at 126-140 containers per second.shell

Easy to use

Containerd provides a daemon and a command line client to manage containers.api

Battle Hardened

Containerd is built on runC, the same container technology powering millions of Docker Engine installations.bash

Compatible with Docker

Docker images can be run with containerd.socket

 

Getting Started

Daemon options

$ containerd -h

NAME:
   containerd - High performance container daemon

USAGE:
   containerd [global options] command [command options] [arguments...]

VERSION:
   0.0.4

AUTHOR(S): 
   @crosbymichael <crosbymichael@gmail.com> 

COMMANDS:
   help, h  Shows a list of commands or help for one command
   
GLOBAL OPTIONS:
   --id "deathstar"                 unique containerd id to identify the instance
   --debug                      enable debug output in the logs
   --state-dir "/run/containerd"            runtime state directory
   -c, --concurrency "10"               set the concurrency level for tasks
   --metrics-interval "1m0s"                interval for flushing metrics to the store
   --listen, -l "/run/containerd/containerd.sock"   Address on which GRPC API will listen
   --oom-notify                     enable oom notifications for containers
   --help, -h                       show help
   --version, -v                    print the version

GRPC API

The API for containerd is with GRPC over a unix socket located at the default location of /run/containerd/containerd.sock.tcp

At this time please refer to the proto definition for the API methods and types.
There is a Go implementation and types checked into this repository but alternate language implementations can be created using the grpc and protoc toolchain.ide

containerd CLI

There is a default cli named ctr based on the GRPC api. This cli will allow you to create and manage containers run with containerd.

NAME:
   ctr - High performance container daemon controller

USAGE:
   ctr [global options] command [command options] [arguments...]

VERSION:
   0.0.4

AUTHOR(S): 
   @crosbymichael <crosbymichael@gmail.com> 

COMMANDS:
   checkpoints  list all checkpoints
   containers   interact with running containers
   events   receive events from the containerd daemon
   help, h  Shows a list of commands or help for one command
   
GLOBAL OPTIONS:
   --debug                  enable debug output in the logs
   --address "/run/containerd/containerd.sock"  address of GRPC API
   --help, -h                   show help
   --version, -v                print the version

Listing containers

$ sudo ctr containers
ID                  PATH                STATUS              PID1
1                   /containers/redis   running             14063
19                  /containers/redis   running             14100

Starting a container

$ ctr containers start -h
NAME:
   start - start a container

USAGE:
   command start [command options] [arguments...]

OPTIONS:
   --checkpoint, -c     checkpoint to start the container from
   --attach, -a         connect to the stdio of the container
$ sudo ctr containers start redis /containers/redis

Kill a container’s process

$ ctr containers kill -h 
NAME:
   kill - send a signal to a container or it's processes

USAGE:
   command kill [command options] [arguments...]

OPTIONS:
   --pid, -p "0"        pid of the process to signal within the container
   --signal, -s "15"    signal to send to the container

Exec another process into a container

$ ctr containers exec -h 
NAME:
   exec - exec another process in an existing container

USAGE:
   command exec [command options] [arguments...]

OPTIONS:
   --id                                         container id to add the process to
   --attach, -a                                 connect to the stdio of the container
   --cwd                                        current working directory for the process
   --tty, -t                                    create a terminal for the process
   --env, -e [--env option --env option]        environment variables for the process
   --uid, -u "0"                                user id of the user for the process
   --gid, -g "0"                                group id of the user for the process

Stats for a container

$ ctr containers stats -h 
NAME:
   stats - get stats for running container

USAGE:
  command stats [arguments...]

List checkpoints

$ sudo ctr checkpoints redis
NAME                TCP                 UNIX SOCKETS        SHELL
test                false               false               false
test2               false               false               false

Create a new checkpoint

$ ctr checkpoints create -h
NAME:
   create - create a new checkpoint for the container

USAGE:
   command create [command options] [arguments...]

OPTIONS:
   --tcp                persist open tcp connections
   --unix-sockets       perist unix sockets
   --exit               exit the container after the checkpoint completes successfully
   --shell              checkpoint shell jobs

Get events

$ sudo ctr events
TYPE                ID                  PID                 STATUS
exit                redis               24761               0

Performance

Starting 1000 containers concurrently runs at 126-140 containers per second.

Overall start times:

[containerd] 2015/12/04 15:00:54   count:        1000
[containerd] 2015/12/04 14:59:54   min:          23ms
[containerd] 2015/12/04 14:59:54   max:         355ms
[containerd] 2015/12/04 14:59:54   mean:         78ms
[containerd] 2015/12/04 14:59:54   stddev:       34ms
[containerd] 2015/12/04 14:59:54   median:       73ms
[containerd] 2015/12/04 14:59:54   75%:          91ms
[containerd] 2015/12/04 14:59:54   95%:         123ms
[containerd] 2015/12/04 14:59:54   99%:         287ms
[containerd] 2015/12/04 14:59:54   99.9%:       355ms
相關文章
相關標籤/搜索