轻量级容器运行时containerd安装

1、yum安装
1.1、获取阿里云YUM源

wget -O /etc/yum.repos.d/docker-ce.repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

1.2、查看YUM源中Containerd软件

yum list | grep containerd
containerd.io.aarch64                                                                    1.6.28-3.2.el9                                 @docker-ce-stable  

1.3、使用yum命令安装

yum -y install containerd.io

1.4、验证安装及启动服务

rpm -qa | grep containerd
containerd.io-1.6.28-3.2.el9.aarch64

1.5、启动containerd服务及开机自启动

systemctl start containerd
systemctl enable containerd

1.6、查看containerd服务状态

systemctl status containerd

1.7、验证服务是否安装正常

ctr version
Client:
  Version:  1.6.28
  Revision: ae07eda36dd25f8a1b98dfbf587313b99c0190bb
  Go version: go1.21.8

Server:
  Version:  1.6.28
  Revision: ae07eda36dd25f8a1b98dfbf587313b99c0190bb
  UUID: c29fa413-0060-4fe3-a127-fb43ffac94c8

2、查看containerd系统启动文件

cat /usr/lib/systemd/system/containerd.service
# Copyright The containerd Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

[Unit]
Description=containerd container runtime
Documentation=https://containerd.io
After=network.target local-fs.target

[Service]
ExecStartPre=-/sbin/modprobe overlay
ExecStart=/usr/bin/containerd  # 系统启动命令

Type=notify
Delegate=yes
KillMode=process
Restart=always
RestartSec=5
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNPROC=infinity
LimitCORE=infinity
LimitNOFILE=infinity
# Comment TasksMax if your systemd version does not supports it.
# Only systemd 226 and above support this version.
TasksMax=infinity
OOMScoreAdjust=-999

[Install]
WantedBy=multi-user.target

3、安装runc
3.1、下载runc

wget https://github.com/opencontainers/runc/releases/download/v1.1.0/runc.amd64 #amd版本
wget https://github.com/opencontainers/runc/releases/download/v1.1.12/runc.arm64 # arm版本

3.2、查看已下载的文件

[root@192 ~]# ls
runc.amd64

3.3、移动可执行文件到指定目录

mv runc.arm64 /usr/sbin/runc

3.4、为runC添加可执行权限

chmod +x /usr/sbin/runc

3.5、验证runc是否安装成功

runc -v
runc version 1.1.12
commit: v1.1.12-0-g51d5e946
spec: 1.0.2-dev
go: go1.20.13
libseccomp: 2.5.4

4、拉取镜像

ctr images pull docker.io/library/nginx:latest

5、查看镜像列表

ctr image ls
REF                            TYPE                                    DIGEST                                                                  SIZE     PLATFORMS                                                                                                               LABELS 
docker.io/library/nginx:latest application/vnd.oci.image.index.v1+json sha256:6db391d1c0cfb30588ba0bf72ea999404f2764febf0f1f196acd5867ac7efa7e 64.1 MiB linux/386,linux/amd64,linux/arm/v5,linux/arm/v7,linux/arm64/v8,linux/mips64le,linux/ppc64le,linux/s390x,unknown/unknown - 

6、运行一个镜像

ctr run -d --net-host docker.io/library/nginx:latest nginx1
--net-host # 使用主机网络
nginx1 启动容器的名称

7、查看正在运行的镜像

ctr container ls
CONTAINER    IMAGE                             RUNTIME                  
nginx1       docker.io/library/nginx:latest    io.containerd.runc.v2  

8、查看已运行容器中运行的进程既tasks

ctr tasks ls
TASK      PID      STATUS    
nginx1    24731    RUNNING

9、进入容器

ctr task exec --exec-id 1 -t nginx1 /bin/bash

9.1、测试是否启动成功

echo "nginx2" > /usr/share/nginx/html/index.html
curl localhost
nginx2 # 显示此名称表示成功请求

10、查看containerd配置文件

cat /etc/containerd/config.toml 
#   Copyright 2018-2022 Docker Inc.

#   Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at

#       http://www.apache.org/licenses/LICENSE-2.0

#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.

disabled_plugins = ["cri"]

#root = "/var/lib/containerd"
#state = "/run/containerd"
#subreaper = true
#oom_score = 0

#[grpc]
#  address = "/run/containerd/containerd.sock"
#  uid = 0
#  gid = 0

#[debug]
#  address = "/run/containerd/debug.sock"
#  uid = 0
#  gid = 0
#  level = "info"

二、containerd常用命令
2.1、只打印镜像名称

ctr image ls -q 
docker.io/library/nginx:alpine
docker.io/library/nginx:latest

2.2、重新打标签

ctr image tag docker.io/library/nginx:alpine harbor.test.com/library/nginx:alpine
harbor.test.com/library/nginx:alpine

2.3、只显示镜像名称

ctr image ls -q
docker.io/library/nginx:alpine
docker.io/library/nginx:latest
harbor.test.com/library/nginx:alpine

2.4、删除镜像(加上 --sync 选项可以同步删除镜像和所有相关的资源)

ctr image rm harbor.test.com/library/nginx:alpine
harbor.test.com/library/nginx:alpine

2.5、验证是否正常删除

ctr image ls -q
docker.io/library/nginx:alpine
docker.io/library/nginx:latest

2.6、查看容器详细配置

ctr container info nginx1

2.7、删除容器

tr container rm nginx
ctr container ls

2.8、创建命名空间

ctr ns create test
ctr ns ls
NAME    LABELS 
default        
test    

2.9、使用 remove 或者 rm 可以删除 namespace

ctr ns rm test
test

2.10、指定命名空间查看容器资源

ctr -n test image ls
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
好的,以下是关于轻量级虚拟化Docker容器实战实验总结: Docker是一种轻量级虚拟化技术,可以帮助我们构建、发布和运行分布式应用程序。以下是一些实验,可以帮助您了解Docker容器的基本操作和使用。 实验1:安装Docker 首先,为了使用Docker,您需要安装Docker引擎。对于Ubuntu系统,可以使用以下命令安装Docker: ``` sudo apt-get update sudo apt-get install docker-ce docker-ce-cli containerd.io ``` 安装完成后,您可以使用以下命令检查Docker是否正确安装: ``` sudo docker run hello-world ``` 如果Docker成功安装,将输出“Hello from Docker!”消息。 实验2:创建和运行Docker容器 接下来,让我们创建并运行一个简单的Docker容器。首先,我们将创建一个Docker镜像,该镜像将在其中运行一个Python应用程序。 1. 创建一个名为“Dockerfile”的文件,并将以下内容添加到其中: ``` FROM python:3 ADD your_script.py / CMD [ "python", "./your_script.py" ] ``` 2. 然后,使用以下命令构建该镜像: ``` sudo docker build -t my-python-app . ``` 3. 构建完成后,使用以下命令运行该容器: ``` sudo docker run my-python-app ``` 这将在容器中运行您的Python应用程序。 实验3:使用Docker Compose编排多个容器 Docker Compose是一种工具,可帮助您编排多个Docker容器。以下是一些基本操作,可以帮助您开始使用Docker Compose。 1. 创建一个名为“docker-compose.yml”的文件,并将以下内容添加到其中: ``` version: '3' services: web: build: . ports: - "5000:5000" redis: image: "redis:alpine" ``` 2. 然后,使用以下命令启动该服务: ``` sudo docker-compose up ``` 这将启动两个容器:一个Python Web应用程序和一个Redis实例。您可以通过访问“localhost:5000”来访问Web应用程序。 实验4:使用Docker Swarm进行集群管理 Docker Swarm是一种工具,可帮助您管理多个Docker节点并将它们组合成一个集群。以下是一些操作,可以帮助您开始使用Docker Swarm。 1. 初始化Swarm: ``` sudo docker swarm init ``` 2. 将其他节点添加到Swarm: ``` sudo docker swarm join --token <token> <ip_address>:<port> ``` 3. 创建一个服务: ``` sudo docker service create --replicas 3 my-python-app ``` 这将在Swarm中创建一个名为“my-python-app”的服务,并创建3个副本。Docker Swarm将自动在集群中的不同节点上运行这些副本。 总结 以上是一些基本的Docker容器实验,可以帮助您了解和使用Docker。Docker具有很多功能,可以帮助您构建、发布和运行分布式应用程序。希望这些实验对您有所帮助!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

运维那些事~

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值