Total Pageviews

Monday, 21 December 2015

Containerd-单独的Container Daemon

Standalone Container Daemon https://containerd.tools/

Docs

For more documentation on various subjects refer to the /docs directory in this repository.

Building

You will need to make sure that you have Go installed on your system and the containerd repository is cloned in your $GOPATH. You will also need to make sure that you have all the dependencies cloned as well. Currently, contributing to containerd is not for the first time devs as many dependencies are not vendored and work is being completed at a high rate. 
After that just run make and the binaries for the daemon and client will be localed in the bin/ directory.

Downloads

The easy way to test and use containerd is to view the releases page for binary downloads. We encourage everyone to use containerd this way until it is out of alpha status.

Performance

Starting 1000 containers concurrently runs at 126-140 containers per second.
from https://github.com/docker/containerd
-------
 nerdctl 初试

自从 Containerd 发布 1.5 以后,nerdctl 工具配合 Containerd 的情况下基本已经可以替换掉 Docker 和 Docker Compose;由于天下苦 Docker 久已,没忍住今天试了试。

一、nerdctl 安装

nerdctl 官方发布包包含两个安装版本:

    Minimal: 仅包含 nerdctl 二进制文件以及 rootless 模式下的辅助安装脚本
    Full: 看名字就能知道是个全量包,其包含了 Containerd、CNI、runc、BuildKit 等完整组件

这时候用脚趾头想我都要一把梭,在一把梭之前先卸载以前安装的 Docker 以及 Containerd 等组件(以下以 Ubuntu 20.04 为例):    

apt purge docker.io containerd -y

然后下载安装包解压启动即可(一把梭真香):

# 下载压缩包
wget https://github.com/containerd/nerdctl/releases/download/v0.8.2/nerdctl-full-0.8.2-linux-amd64.tar.gz

# 解压安装
tar Cxzvvf /usr/local nerdctl-full-0.8.2-linux-amd64.tar.gz

# 启动 containerd 和 buildkitd
systemctl enable --now containerd
systemctl enable --now buildkit

二、使用

启动完成后就可以通过 ctr、crictl 命令测试 containerd 是否工作正常了;没问题的话继续折腾 nerdctl。
2.1、Docker CLI 兼容

Docker CLI 的兼容具体情况可以从 https://github.com/containerd/nerdctl#command-reference 中查看相关说明;既然是为了兼容 Docker CLI,那么在运行时只需要把 docker 命令换成 nerdctl 命令即可:
    

vm.node ➜ ~ nerdctl run -d --name test -p 8080:80 nginx:alpine
80342ff329574ab290c212b2b786b52dd0c3f3209ee8e9e06878259dd1186879
vm.node ➜  ~ nerdctl ps
CONTAINER ID    IMAGE                             COMMAND                   CREATED          STATUS    PORTS                   NAMES
80342ff32957    docker.io/library/nginx:alpine    "/docker-entrypoint.…"    3 seconds ago    Up        0.0.0.0:8080->80/tcp    test
vm.node ➜ ~ curl 10.0.0.5:8080
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

唯一需要注意的是部分命令选项还是有一定不兼容,比如 run 的时候 -d 和 -t 不能一起用,--restart 策略不支持等,但是通过列表可以看到大部分 cli 都已经完成了。

2.2、Docker Compose 兼容

由于环境不同吧,说实话 Docker Compose 兼容才是吸引最大的一点;因为现实环境中很少有直接 docker run... 这么干的,大部分不重要服务都是通过 docker-compose 启动的;而目前来说 nerdctl 配合 CNI 等已经完成了大部分 Compose 的兼容:

docker-compose.yaml

version: '3.7'
services:
  cloudreve:
    image: mritd/cloudreve:relativepath
    container_name: cloudreve
    restart: always
    ports:
    - "5212:5212"
    - "5443:5443"
    volumes:
    - ./config:/etc/cloudreve
    - data:/data
    - shared:/downloads
    command: ["-c","/etc/cloudreve/conf.ini"]
volumes:
  shared:
  data:

运行测试:    

vm.node ➜ nerdctl compose up -d
INFO[0000] Creating network test_default
INFO[0000] Ensuring image mritd/cloudreve:relativepath
INFO[0000] Creating container cloudreve

不过目前比较尴尬的是 compose 还不支持 ps 命令,同时如果 volume 了宿主机目录,如果目录不存在也不会自动创建;logs 命令似乎也有 BUG。

三、总结

nerdctl 目前还有很多不完善的地方,比如 cp 等命令不支持,compose 命令不完善,BuildKit 还不支持多平台交叉编译等;所以简单玩玩倒是可以,距离生产使用还需要一些时间,但是总体来说未来可期,相信不久以后我们会离 Docker 越来越远。