描述: 事实上,Docker 和 Containerd 是可以同时使用的,只不过 Docker 默认使用的 Containerd 的命名空间不是 default,而是 moby,此处为了更方便我们学习可以将 Docker 与 Containerd 联合使用。

Step 1.安装配置 containerd

yum install -y yum-utils
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum makecache fast yum -y install containerd.io # cat /etc/containerd/config.toml
disabled_plugins = []
imports = []
oom_score = 0
plugin_dir = ""
required_plugins = []
root = "/var/lib/containerd"
state = "/run/containerd"
temp = ""
version = 2 [cgroup]
path = "" [debug]
address = ""
format = ""
gid = 0
level = ""
uid = 0 [grpc]
address = "/run/containerd/containerd.sock"
gid = 0
max_recv_message_size = 16777216
max_send_message_size = 16777216
tcp_address = ""
tcp_tls_ca = ""
tcp_tls_cert = ""
tcp_tls_key = ""
uid = 0 [metrics]
address = ""
grpc_histogram = false [plugins] [plugins."io.containerd.gc.v1.scheduler"]
deletion_threshold = 0
mutation_threshold = 100
pause_threshold = 0.02
schedule_delay = "0s"
startup_delay = "100ms" [plugins."io.containerd.grpc.v1.cri"]
device_ownership_from_security_context = false
disable_apparmor = false
disable_cgroup = false
disable_hugetlb_controller = true
disable_proc_mount = false
disable_tcp_service = true
enable_selinux = false
enable_tls_streaming = false
enable_unprivileged_icmp = false
enable_unprivileged_ports = false
ignore_image_defined_volumes = false
max_concurrent_downloads = 3
max_container_log_line_size = 16384
netns_mounts_under_state_dir = false
restrict_oom_score_adj = false
sandbox_image = "registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.6"
selinux_category_range = 1024
stats_collect_period = 10
stream_idle_timeout = "4h0m0s"
stream_server_address = "127.0.0.1"
stream_server_port = "0"
systemd_cgroup = false
tolerate_missing_hugetlb_controller = true
unset_seccomp_profile = "" [plugins."io.containerd.grpc.v1.cri".cni]
bin_dir = "/opt/cni/bin"
conf_dir = "/etc/cni/net.d"
conf_template = ""
ip_pref = ""
max_conf_num = 1 [plugins."io.containerd.grpc.v1.cri".containerd]
default_runtime_name = "runc"
disable_snapshot_annotations = false
discard_unpacked_layers = false
ignore_rdt_not_enabled_errors = false
no_pivot = false
snapshotter = "stargz" [plugins."io.containerd.grpc.v1.cri".containerd.default_runtime]
base_runtime_spec = ""
cni_conf_dir = ""
cni_max_conf_num = 0
container_annotations = []
pod_annotations = []
privileged_without_host_devices = false
runtime_engine = ""
runtime_path = ""
runtime_root = ""
runtime_type = "" [plugins."io.containerd.grpc.v1.cri".containerd.default_runtime.options] [plugins."io.containerd.grpc.v1.cri".containerd.runtimes] [plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc]
base_runtime_spec = ""
cni_conf_dir = ""
cni_max_conf_num = 0
container_annotations = []
pod_annotations = []
privileged_without_host_devices = false
runtime_engine = ""
runtime_path = ""
runtime_root = ""
runtime_type = "io.containerd.runc.v2" [plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc.options]
BinaryName = ""
CriuImagePath = ""
CriuPath = ""
CriuWorkPath = ""
IoGid = 0
IoUid = 0
NoNewKeyring = false
NoPivotRoot = false
Root = ""
ShimCgroup = ""
SystemdCgroup = true [plugins."io.containerd.grpc.v1.cri".containerd.untrusted_workload_runtime]
base_runtime_spec = ""
cni_conf_dir = ""
cni_max_conf_num = 0
container_annotations = []
pod_annotations = []
privileged_without_host_devices = false
runtime_engine = ""
runtime_path = ""
runtime_root = ""
runtime_type = "" [plugins."io.containerd.grpc.v1.cri".containerd.untrusted_workload_runtime.options] [plugins."io.containerd.grpc.v1.cri".image_decryption]
key_model = "node" [plugins."io.containerd.grpc.v1.cri".registry]
config_path = "" [plugins."io.containerd.grpc.v1.cri".registry.auths] [plugins."io.containerd.grpc.v1.cri".registry.configs] [plugins."io.containerd.grpc.v1.cri".registry.headers] [plugins."io.containerd.grpc.v1.cri".registry.mirrors]
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."docker.io"]
endpoint = ["https://docker.mirrors.ustc.edu.cn","http://hub-mirror.c.163.com"]
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."gcr.io"]
endpoint = ["https://gcr.mirrors.ustc.edu.cn"]
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."k8s.gcr.io"]
endpoint = ["https://gcr.mirrors.ustc.edu.cn/google-containers/"]
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."quay.io"]
endpoint = ["https://quay.mirrors.ustc.edu.cn"] [plugins."io.containerd.grpc.v1.cri".x509_key_pair_streaming]
tls_cert_file = ""
tls_key_file = "" [plugins."io.containerd.internal.v1.opt"]
path = "/opt/containerd" [plugins."io.containerd.internal.v1.restart"]
interval = "10s" [plugins."io.containerd.internal.v1.tracing"]
sampling_ratio = 1.0
service_name = "containerd" [plugins."io.containerd.metadata.v1.bolt"]
content_sharing_policy = "shared" [plugins."io.containerd.monitor.v1.cgroups"]
no_prometheus = false [plugins."io.containerd.runtime.v1.linux"]
no_shim = false
runtime = "runc"
runtime_root = ""
shim = "containerd-shim"
shim_debug = false [plugins."io.containerd.runtime.v2.task"]
platforms = ["linux/amd64"]
sched_core = false [plugins."io.containerd.service.v1.diff-service"]
default = ["walking"] [plugins."io.containerd.service.v1.tasks-service"]
rdt_config_file = "" [plugins."io.containerd.snapshotter.v1.aufs"]
root_path = "" [plugins."io.containerd.snapshotter.v1.btrfs"]
root_path = "" [plugins."io.containerd.snapshotter.v1.devmapper"]
async_remove = false
base_image_size = ""
discard_blocks = false
fs_options = ""
fs_type = ""
pool_name = ""
root_path = "" [plugins."io.containerd.snapshotter.v1.native"]
root_path = "" [plugins."io.containerd.snapshotter.v1.overlayfs"]
root_path = ""
upperdir_label = false [plugins."io.containerd.snapshotter.v1.zfs"]
root_path = "" [plugins."io.containerd.tracing.processor.v1.otlp"]
endpoint = ""
insecure = false
protocol = "" [proxy_plugins]
[proxy_plugins.stargz]
type = "snapshot"
address = "/run/containerd-stargz-grpc/containerd-stargz-grpc.sock" [stream_processors] [stream_processors."io.containerd.ocicrypt.decoder.v1.tar"]
accepts = ["application/vnd.oci.image.layer.v1.tar+encrypted"]
args = ["--decryption-keys-path", "/etc/containerd/ocicrypt/keys"]
env = ["OCICRYPT_KEYPROVIDER_CONFIG=/etc/containerd/ocicrypt/ocicrypt_keyprovider.conf"]
path = "ctd-decoder"
returns = "application/vnd.oci.image.layer.v1.tar" [stream_processors."io.containerd.ocicrypt.decoder.v1.tar.gzip"]
accepts = ["application/vnd.oci.image.layer.v1.tar+gzip+encrypted"]
args = ["--decryption-keys-path", "/etc/containerd/ocicrypt/keys"]
env = ["OCICRYPT_KEYPROVIDER_CONFIG=/etc/containerd/ocicrypt/ocicrypt_keyprovider.conf"]
path = "ctd-decoder"
returns = "application/vnd.oci.image.layer.v1.tar+gzip" [timeouts]
"io.containerd.timeout.bolt.open" = "0s"
"io.containerd.timeout.shim.cleanup" = "5s"
"io.containerd.timeout.shim.load" = "5s"
"io.containerd.timeout.shim.shutdown" = "3s"
"io.containerd.timeout.task.state" = "2s" [ttrpc]
address = ""
gid = 0
uid = 0 systemctl start containerd && systemctl enable containerd && systemctl status containerd

Step 2.在宿主机中安装docker客户端及服务

yum install -y yum-utils
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum makecache fast yum -y install docker-ce tee /etc/docker/daemon.json <<-'EOF'
{
"live-restore": true,
"registry-mirrors": ["https://hub-mirror.c.163.com","https://bmtrgdvx.mirror.aliyuncs.com","https://y9lmbx5j.mirror.aliyuncs.com"],
"log-driver":"json-file",
"log-opts":{
"max-size" :"50m",
"max-file":"3"
}
}
EOF

Step 3.编辑/etc/systemd/system/multi-user.target.wants/docker.service文件并为其新增 --containerd如下启动项:--containerd /run/containerd/containerd.sock

vim /etc/systemd/system/multi-user.target.wants/docker.service
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock --cri-containerd --debug # - 重新加载配置
systemctl daemon-reload systemctl enable docker && systemctl start docker && systemctl status docker

Step 4.打开两个Shell终端一个采用 docker 运行一个 busybox 容器,另外一个查看对比。

$ docker run --rm -it busybox sh
# / # ip addr
# 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue qlen 1000
# link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
# inet 127.0.0.1/8 scope host lo
# valid_lft forever preferred_lft forever
# 8: eth0@if9: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu 1500 qdisc noqueue
# link/ether 02:42:ac:11:00:02 brd ff:ff:ff:ff:ff:ff
# inet 172.17.0.2/16 brd 172.17.255.255 scope global eth0 # 关键点
# valid_lft forever preferred_lft forever
# / # cat /etc/hosts
# 127.0.0.1 localhost
# 172.17.0.2 51dcdf68d3b8 # 采用 ctr 在 moby 名称空间下查看docker创建的容器以及Task PID
$ ctr -n moby c ls
# CONTAINER IMAGE RUNTIME
# 51dcdf68d3b8bf4c9707c9059e33f9570cb83725355595e77cf433dd3e25b64b - io.containerd.runc.v2
$ ctr -n moby t ls
# TASK PID STATUS
# 51dcdf68d3b8bf4c9707c9059e33f9570cb83725355595e77cf433dd3e25b64b 131926 RUNNING # 验证获取到的 Task PID 下其 net 相关信息
$ grep "172.17.0.2" /proc/131926/net/fib_trie
|-- 172.17.0.2
|-- 172.17.0.2 # 采用 ctr 进入 Docker 创建的容器
$ ctr -n moby t exec -t --exec-id $RANDOM 51dcdf68d3b8bf4c9707c9059e33f9570cb83725355595e77cf433dd3e25b64b sh
# / # ip addr | grep "172.17.0.2"
# inet 172.17.0.2/16 brd 172.17.255.255 scope global eth0
# / # hostname
# 51dcdf68d3b8

Tips : containerd 引入了 namespace 概念, 每个image和container都会在各自的namespace下可见, 目前k8s会使用 k8s.io 以及 default 作为命名空间。

Tips : 当导入本地镜像时ctr不支持压缩。

Tips : 通过ctr containers create创建容器后,只是一个静态的容器,容器中的用户进程并没有启动,所以还需要通过ctr task start来启动容器进程。 当然也可以用ctr run的命令直接创建并运行容器。在进入容器操作时与docker不同的是,必须在ctr task exec命令后指定--exec-id参数,这个id可以随便写只要唯一就行。

Tips : ctr没有stop容器的功能,只能暂停(ctr task pause)或者杀死(ctr task kill)容器

Docker 与 Containerd 并用配置的更多相关文章

  1. 配置docker官方源并用yum安装docker

    一.docker的官方安装文档: https://docs.docker.com/engine/installation/linux/centos/ 由docker给的文档可以看出它也只是去配置了一个 ...

  2. Docker与Containerd使用区别

    文章转载自:https://cloud.tencent.com/developer/article/1984040 Kubernetes 在 1.24 版本里弃用并移除 docker shim,这导致 ...

  3. Docker remote API简单配置使用

    1.启动docker remote API的方式如下: docker -d -H uninx:///var/run/docker.sock -H tcp://0.0.0.0:5678 2.但是为了伴随 ...

  4. Docker Mysql主从同步配置搭建

    Docker Mysql主从同步配置搭建 建立目录 在虚拟机中建立目录,例如路径/home/mysql/master/data,目录结构如下: Linux中 新建文件夹命令:mkdir 文件夹名 返回 ...

  5. centos7 docker使用https_proxy 代理配置

    centos7 docker使用https_proxy 代理配置 背景: 内网的centos主机不能上网,通过同网段的windows设置代理上网,yum.conf配置http代理是可以的,但是dock ...

  6. zabbix docker - 安装和初始化配置

    zabbix docker - 安装和初始化配置 安装zabbix server docker-mysql版本 zabbix server支持不同的数据库(详见zabbix的docker hub),这 ...

  7. docker+redis安装与配置,主从+哨兵模式

    docker+redis安装与配置 docker安装redis并且使用redis挂载的配置启动 1.拉取镜像 docker pull redis:3.2 2.准备准备挂载的目录和配置文件 首先在/do ...

  8. Docker简介与安装配置

    目录 Docker简介 什么是Docker 为啥要用容器 Docker Engine Docker架构说明 Docker安装 Docker版本介绍 Ubuntu安装docker-ce CentOS7安 ...

  9. Docker的安装,配置,更新和卸载

    我们可以在Linux中安装Docker并运行Hello world应用程序.通过下面这些操作,我们将会学到更多有关于Docker的基础特征.我们将会学到如何: 安装Docker引擎 在一个容器中运行软 ...

随机推荐

  1. 【python基础】第19回 多层,有参装饰器 递归 二分法

    本章内容概要 1. 多层装饰器 2. 有参装饰器 3. 递归函数 4. 算法(二分法) 本章内容详解 1. 多层装饰器 1.1 什么是多层装饰器 多层装饰器是从下往上依次执行,需要注意的是,被装饰的函 ...

  2. 如何借助Chrome Tool Dev 帮助前端开发

    11111111111111111111111111111111111111111111111111

  3. 【Python3】列表字典集合元组

    1 列表 1.1 定义与索引 在Python中,第一个列表元素的下标为 0通过将索引指定为 -1 可以让Python返回最后一个列表元素 inventory = ['sword', 'armor', ...

  4. 可变参数和Collections集合工具类

    可变参数 /** * 可变参数:jdk1.5后出现的新特性 * 使用前期: * 当方法的参数列表数据类型已经确定的时候但是参数的个数不确定的时候就可以使用可变参数 * 使用格式:定义方法的时候使用 * ...

  5. React报错之Cannot find name

    正文从这开始~ .tsx扩展名 为了在React TypeScript中解决Cannot find name报错,我们需要在使用JSX文件时使用.tsx扩展名,在你的tsconfig.json文件中把 ...

  6. YII学习总结4(cookie操作)

    cookie操作 <?php namespace app\controllers; use yii\web\Controller; use yii\web\Cookie; class Hello ...

  7. Mqtt开发笔记:windows下C++ ActiveMQ客户端介绍、编译和使用

    前话   项目需求,需要使用到mqtt协议,之前编译QtMqtt库,不支持队列模式queue(点对点),只支持订阅/发布者模式.,所以使用C++ ActiveMQ实现.   MQTT协议 简介   M ...

  8. WPF 截图控件之移除控件(九)「仿微信」

    WPF 截图控件之移除控件(九)「仿微信」 WPF 截图控件之移除控件(九)「仿微信」 作者:WPFDevelopersOrg 原文链接: https://github.com/WPFDevelope ...

  9. @Autowired注解 --required a single bean, but 2 were found出现的原因以及解决方法

    @Autowired注解是spring用来支持依赖注入的核心利器之一,但是我们或多或少都会遇到required a single bean, but 2 were found(2可能是其他数字)的问题 ...

  10. GCC常见命令

    rwx 对于目录和文件的区别 文件 目录 r 文件的内容可以被查看.支持cat.more.head...vim 目录的内容可以被查看.ls.tree w 文件的内容可以被添加.修改.删除.vim &g ...