当前位置: 首页 > 科技观察

AnintroductionthattakesyoutounderstandContainerdvsDocker

时间:2023-03-13 07:35:52 科技观察

Recently,thecompanyplanstonolongerusedockerinnewproducts,butusecontainerdastheruntime.Asforthereason,hedidn'ttellusdirectly.So,Iplantofindoutbymyself;andcompareitwithdockertoseethedifferencebetweenthetwo.Ibelieveeveryoneisalreadyveryfamiliarwiththeintroductionofdocker,soIwon'tintroduceit.Heretointroducecontainerd.github上针对containerd的介绍如下:containerdisanindustry-standardcontainerruntimewithanemphasisonsimplicity,robustnessandportability.ItisavailableasadaemonforLinuxandWindows,whichcanmanagethecompletecontainerlifecycleofitshostsystem:imagetransferandstorage,containerexecutionandsupervision,low-levelstorageandnetworkattachments,etc.大致意思就是说Containerd是一个强调简单性、健壮性和可移植性的行业标准容器运行hour.Itcanbeusedonwindowsandlinux,andcanmanagetheentirelifecycleofthecontaineronthehost,includingimagetransfer,containercreationandmanagement,low-levelstorageandnetworkattachments,etc.Itsstructureisasfollows:FunctionFriendswhohaveuseddockermustbefamiliarwithdocker.Hereweonlytalkaboutthefunctionofcontainerd.Thefunctionsofcontainerdareasfollows:SupportOCI'simagestandardOCI'scontainerruntimeimagepushandpullContainerruntimelifecyclemanagementMulti-tenantimagestoragenetworkmanagementandnetworknamespacemanagement,supportcontainernetworktojoinexistingnamespacesComparenext,amultifacetedcomparisonofdockerandcontainerd.Seewhatarethedifferencesbetweenthetwo,andhelpyouchoosetherightonetouseinthefuture.使用k8s时,使用docker和containerd的调用链如下:不难看出,使用containerd时,调用链更短,不再需要经过dockershim和docker数据目录。相信大家都知道docker默认的数据目录在/var/lib/docker目录下;切换到containerd时,数据目录默认为/var/lib/containerd。我们在使用k8s的时候,如果使用docker作为运行时,容器程序日志其实是放在磁盘上的。由docker负责。/var/log/pod和/var/log/container下的日志文件会软连接到/var/lib/docker下对应的日志文件。如果需要为日志配置一些参数,可以直接修改docker配置文件。;而如果我们现在使用containerd作为运行时,kubelet将负责容器日志的存储,/var/log/container下的日志文件会软链接到/var/log/pod下的日志文件.如果需要调整Log参数,需要修改kubelet相关配置CNI当使用docker作为runtime时,kubelet中的docker-shim负责调用cni;当使用containerd作为runtime时,containerd内置的containerd-cri负责调用cni[plugins."io.containerd.grpc.v1.cri".cni]bin_dir="/opt/cni/bin"conf_dir="/etc/cni/net.d"streamservice熟悉k8s的朋友都知道,kubectlexec、kubeletlog等命令需要通过apiserver与容器通信,这就涉及到streamingservice。dockerAPI本身是支持的,kubelet中的docker-shim是通过dockerAPIstream转发的;但是containerd必须单独配置[plugins."io.containerd.grpc.v1.cri"]stream_idle_timeout="4h0m0s"stream_server_address="在127.0.0.1"stream_server_port="0"enable_tls_streaming=false命令使用containerd作为运行时之后,常用命令也发生了变化。这里有两个例子。另外,在使用containerd时,可以安装nerdctl工具来配合containerd命名空间使用,这与使用docker命令是一样的。命名空间containerd引入了命名空间。命名空间允许多个消费者使用同一个容器而不会相互冲突。它的优点是内容可以共享,但仍然与容器和图像分离。因此,在使用containerd相关命令时,需要添加-n命名空间参数。命名空间允许多个消费者使用同一个容器而不会相互冲突。它作为共享内容的好处,但仍然与容器和图像分离。总结总的来说,containerd和docker还是有很多区别的,但是最终要达到的效果是一样的。至于我们在使用k8s的过程中使用哪一个作为runtime,还是要根据实际情况来选择。参考https://github.com/containerd/containerd本文转载自微信公众号《运维开发故事》