Containerd容器数据持久化存储,命名空间共享,与docker的集成

1.  Containerd容器数据持久化存储:

## 实现把宿主机目录挂载至Containerd容器中,实现容器数据持久化存储
[root@node2 ~]# ctr c create busybox:latest busybox3 --mount 
type=bind,src=/tmp,dst=/hostdir,options=rbind:rw

创建一个静态容器,实现宿主机目录与容器目录挂载
src=/tmp 表示宿主机目录
dst=/hostdir 表示容器中目录

## 查看容器列表:
[root@node2 ~]# ctr c ls
CONTAINER    IMAGE             RUNTIME                  
busybox      busybox:latest    io.containerd.runc.v2    
busybox2     busybox:latest    io.containerd.runc.v2    
busybox3     busybox:latest    io.containerd.runc.v2 

## 启动容器
[root@node2 ~]# ctr t start -d busybox3

测试容器中的数据是否持久化:

## 进入容器
[root@node2 ~]# ctr -n default task exec --exec-id $RANDOM -t busybox3 sh
/ # 
/ # ls /
bin      dev      etc      home     hostdir  proc     root     run      sys      tmp      usr      var
/ # echo 111 > /hostdir/1.txt
/ # exit

## 查看宿主机的/tmp目录下是否有1.txt文件
[root@node2 ~]# cat /tmp/1.txt 
111

2.  与其它Containerd容器共享命名空间:由于 Containerd 也有 namespaces 的概念,对于上层编排系统的支持,ctr 客户端 主要区分了 3 个命名空间分别是k8s.io(k8s命名空间)、moby(docker命名空间)和default(默认的命名空间)

## 查看任务列表:
[root@node2 ~]# ctr tasks ls
TASK        PID      STATUS
busybox     1510    RUNNING
busybox3    1982    RUNNING

## 创建共享的容器:
[root@node2 ~]# ctr container create --with-ns "pid:/proc/1982/ns/pid" 
busybox:latest busybox4

## 启动容器
[root@node2 ~]# ctr t start -d busybox4 bash

## 进入容器
[root@node2 ~]# ctr t -n default exec --exec-id $RANDOM -t busybox3 sh

[root@node2 ~]# ctr t -n default exec --exec-id $RANDOM -t busybox4 sh

3.  Docker集成Containerd实现容器管理:

        1>.  安装docker:

## 准备Docker安装YUM源
[root@node2 ~]# wget -O /etc/yum.repos.d/docker-ce.repo https://mirrors.aliyun
.com/docker-ce/linux/centos/docker-ce.repo

## 安装Docker-ce
[root@node2 ~]# yum -y install docker-ce

        2>. 修改Docker服务文件:

[root@node2 ~]# vim /usr/lib/systemd/system/docker.service

将其中[Service]标签中的
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
修改为:
ExecStart=/usr/bin/dockerd --containerd  /run/containerd/containerd.sock --debug

        3>.  重启docker服务:

## 重启docker daemon服务
[root@node2 ~]# systemctl daemon-reload

[root@node2 ~]# systemctl start docker

通过docker创建容器并运行容器后,通过" ctr ns -f "会发现新增了一个docker的命名空间

[root@node2 ~]# docker run -d busybox  ##运行docker容器

[root@node2 ~]# docker ps -all ##查看docker镜像列表

## 查看命名空间
[root@node2 ~]# ctr ns ls
NAME    LABELS 
default        
moby 

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值