源创宝库吧 新一代精品资源网 在线工具箱 此位置招租 SanS三石导航页 ⚡免费影视资源库丨极速无广告⚡ 此位置招租 此位置招租 此位置招租 此位置招租 此位置招租 ⚡免费影视资源库丨极速无广告⚡ 此位置招租 此位置招租 此位置招租 此位置招租 此位置招租 ⚡免费影视资源库丨极速无广告⚡ 此位置招租 此位置招租 此位置招租 此位置招租 此位置招租 ⚡免费影视资源库丨极速无广告⚡ 此位置招租
返回列表 发布新帖
查看: 102|回复: 4

[技术交流] Podman介绍

  在线 
灌水成绩
127
203
809
主题
回帖
积分

等级头衔
UID : 83
等级 : 版主

积分成就
威望 : 93 点
贡献 : 381 点
蛋壳 : 5736 枚
在线时间 : 1311 小时
注册时间 : 2024-4-17
最后登录 : 2024-9-20

荣誉勋章
发表于 2024-6-2 11:45:33 | 查看全部 |阅读模式 来自: 中国–黑龙江–七台河

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
# Podman介绍

Podman 是一个开源的容器运行时项目,可在大多数 Linux 平台上使用。Podman 提供与 Docker 非常相似的功能。正如前面提到的那样,它不需要在你的系统上运行任何守护进程,并且它也可以在没有 root 权限的情况下运行。
Podman 可以管理和运行任何符合 OCI(Open Container Initiative)规范的容器和容器镜像。Podman 提供了一个与 Docker 兼容的命令行前端来管理 Docker 镜像。

> 1. Podman 官网地址:https://podman.io/
> 2. Podman 项目地址:https://github.com/containers/libpod

#### Podman 和docker不同之处?

1. docker 需要在我们的系统上运行一个守护进程(docker daemon),而podman 不需要
2. 启动容器的方式不同:
        `docker cli` 命令通过API跟 `Docker Engine(引擎)`交互告诉它我想创建一个container,然后`docker Engine`才会调用`OCI container runtime(runc)`来启动一个container。这代表container的process(进程)不会是`Docker CLI`的`child process(子进程)`,而是`Docker Engine`的`child process`。
        `Podman`是直接给`OCI containner runtime(runc)`进行交互来创建container的,所以`container process`直接是`podman`的`child process`。
3. 因为docke有docker daemon,所以docker启动的容器支持`--restart`策略,但是podman不支持,如果在k8s中就不存在这个问题,我们可以设置pod的重启策略,在系统中我们可以采用编写systemd服务来完成自启动
4. docker需要使用root用户来创建容器,但是podman不需要

## Podman安装

```
# yum -y install podman
```

## Podman命令

### 镜像管理命令

#### 镜像搜索 podman search

```
[root@node4 ~]# podman search centos
INDEX    NAME      DESCRIPTION           STARS   OFFICIAL   AUTOMATED                           
Podman.io  Podman.io/blacklabelops/centos CentOS Base Image! Built and Updates Daily!       1                  [OK]        

INDEX
NAME     镜像名字
DESCRIPTION        描述
SATRS                                星级  数字越大代表使用人数越多
OFFICIAL                是否为官方镜像
AUTOMATED               


拓展知识:
根据本地的/etc/containers/registries.conf文件中定义的去搜索
#默认情况下,使用podman搜索从容器仓库中搜索镜像时,基于registries.conf文件,podman按顺序在registry.redhat.io、registry.access.redhat.com、quay.io和docker.io中查找请求的镜像。
[registries.search]
registries = ['registry.redhat.io', 'registry.access.redhat.com', 'quay.io', 'docker.io']

#要添加对不需要身份验证的容器仓库(不安全容器仓库)的访问,必须在[registries.Unsecure]部分下添加该容器仓库的名称。
[registries.insecure]
registries = []

#要禁止从本地系统访问的任何容器仓库都需要添加到[registries.block]部分下。
[registries.block]
registries = []


关于配置容器容器仓库,您还应该了解以下几点:
1、确保每个容器仓库都用单引号括起来。
2、如果为registries=值设置了多个仓库,则必须用逗号分隔这些仓库。
3、仓库可以通过IP地址或主机名来标识。
4、如果仓库使用非标准端口(即,安全端口不是TCP端口443,不安全端口不是80),则应使用仓库名输入该端口号。例如:host.example.com:9999
5、按照Registries.conf文件每个部分的显示顺序搜索仓库。
6、如果您是运行podman和相关工具的普通用户(无根),则可以创建自己的registries.conf文件来覆盖默认设置。
```

#### 本地镜像查看 podman images

```
[root@node4 ~]# podman images
REPOSITORY                    TAG      IMAGE ID       CREATED         SIZE
Podman.io/blacklabelops/centos latest   73f5fb57a402   13 months ago   391 MB
```

#### 从仓库镜像拉取 podman pull [imange_name]

```
[root@node4 ~]# podman pull Podman.io/blacklabelops/centos
Trying to pull Podman.io/blacklabelops/centos...Getting image source signatures
Copying blob 18b8eb7e7f01: 69.75 MiB / 69.96 MiB [=============================]
Copying blob 18b8eb7e7f01: 69.96 MiB / 69.96 MiB [=========================] 33s
Copying blob 18b8eb7e7f01: 69.96 MiB / 69.96 MiB [=========================] 33s
Copying blob 9d438d3ad7e8: 61.22 MiB / 61.22 MiB [=========================] 33s
Copying config 73f5fb57a402: 3.98 KiB / 3.98 KiB [==========================] 0s
Writing manifest to image destination
Storing signatures
73f5fb57a402c17df1a74ddb154c4d2e2cd30c366e224d9cb6087ab9c6339d58
```

#### 本地镜像删除 podman rmi [IMAGE_ID|REPOSITORY]

```
方法一: podman rmi IMAGE_ID
[root@node4 ~]# podman rmi 73f5fb57a402
73f5fb57a402c17df1a74ddb154c4d2e2cd30c366e224d9cb6087ab9c6339d58
方法二: podman rmi REPOSITORY
[root@node4 ~]# podman rmi Podman.io/blacklabelops/centos
73f5fb57a402c17df1a74ddb154c4d2e2cd30c366e224d9cb6087ab9c6339d58
```

#### 镜像上传到仓库 podman push

#### 镜像管理综合命令 podman image

```
[root@node4 ~]# podman image
NAME:
   podman image - Manage images

USAGE:
   podman image command [command options] [arguments...]

COMMANDS:
     build     Build an image using instructions from Podmanfiles
     #根据Podmanfiles创建image
     history   Show history of a specified image
     #显示指定镜像的历史信息
     import    Import a tarball to create a filesystem image
     #导入一个文件系统压缩包
     exists    Check if an image exists in local storage
     #检查本地是否存在某个镜像
     inspect   Displays the configuration of a container or image
     #显示容器或镜像的详细信息
     load      Load an image from Podman archive
     #将镜像文件导入到镜像仓库
     list, ls  list images in local storage
     #列出本地存储中的镜像
     prune     Remove unused images
     #移除未使用的镜像
     pull      Pull an image from a registry
     #下载一个镜像到本地
     push      Push an image to a specified destination
     #上传一个镜像到仓库
     rm        removes one or more images from local storage
     #删除一个或多个本地镜像
     save      Save image to an archive
     #将一个镜像保存为一个镜像文件
     tag       Add an additional name to a local image
     #添加一个额外的名称给本地镜像
     trust     Manage container image trust policy
     #信任容器镜像
     sign      Sign an image
     #生成镜像签名,可以根据签名验证镜像的完整性

OPTIONS:
   --help, -h  show help
   
   
镜像历史信息
[root@node4 ~]# podman image history 73f5fb57a402
ID             CREATED         CREATED BY                                      SIZE      COMMENT
73f5fb57a402   13 months ago   /bin/sh -c #(nop) LABEL maintainer=Steffen...   0B        
      13 months ago   |1 BUILD_DATE=06/10/2018-01:06+0200 /bin/s...   64.2MB   
      13 months ago   /bin/sh -c #(nop) ARG BUILD_DATE=undefined      64.2MB   
      15 months ago   /bin/sh -c #(nop) CMD ["/bin/bash"]             64.2MB   
      15 months ago   /bin/sh -c #(nop) LABEL name=CentOS Base I...   64.2MB   
      15 months ago   /bin/sh -c #(nop) ADD file:d6a1da927f0b7a7...   73.36MB   


镜像导入来自系统压缩包 导入时文件越大越慢
[root@node4 ~]# podman image import centos8.tar
Getting image source signatures
Copying blob 84d82847ae58: 1.29 GiB / 1.31 GiB [===============================]
Copying blob 84d82847ae58: 1.31 GiB / 1.31 GiB [===========================] 14s
Copying config 2d42f6c756bc: 419 B / 419 B [================================] 0s
Writing manifest to image destination
Storing signatures
2d42f6c756bc02640bbb77319b5f1b3a2c51f70fd64d4919d8eb5c0d078c87a7


监测本地镜像是否存在,结合$?
[root@node4 ~]# podman image exists 2d42f6c756bc;echo $?
0
[root@node4 ~]# podman image exists 2d42f6c756bcxxxx;echo $?
1



镜像下载
[root@node4 ~]# podman image pull Podman.io/blacklabelops/centos
Trying to pull Podman.io/blacklabelops/centos...Getting image source signatures
Copying blob 18b8eb7e7f01: 69.92 MiB / 69.96 MiB [=============================]
Copying blob 18b8eb7e7f01: 69.96 MiB / 69.96 MiB [=========================] 23s
Copying blob 18b8eb7e7f01: 69.96 MiB / 69.96 MiB [=========================] 24s
Copying blob 9d438d3ad7e8: 61.22 MiB / 61.22 MiB [=========================] 24s
Copying config 73f5fb57a402: 3.98 KiB / 3.98 KiB [==========================] 0s
Writing manifest to image destination
Storing signatures
73f5fb57a402c17df1a74ddb154c4d2e2cd30c366e224d9cb6087ab9c6339d58

镜像查看  list
[root@node4 ~]# podman image list
REPOSITORY                       TAG      IMAGE ID       CREATED         SIZE
Podman.io/blacklabelops/centos   latest   73f5fb57a402   13 months ago   391 MB

镜像查看  ls
[root@node4 ~]# podman image ls
REPOSITORY                       TAG      IMAGE ID       CREATED         SIZE
Podman.io/blacklabelops/centos   latest   73f5fb57a402   13 months ago   391 MB

镜像删除
[root@node4 ~]# podman image rm 73f5fb57a402
73f5fb57a402c17df1a74ddb154c4d2e2cd30c366e224d9cb6087ab9c6339d58




[root@node4 ~]# podman image tag 2d42f6c756bc tyschool_centos8_1905
[root@node4 ~]# podman image list
REPOSITORY                        TAG      IMAGE ID       CREATED       SIZE
localhost/tyschool_centos8_1905   latest   2d42f6c756bc   5 hours ago   1.4 GB


导出一个镜像到文件 -o output
[root@node4 ~]# podman image save -o centos_7_base Podman.io/blacklabelops/centos
Getting image source signatures
Copying blob 129b697f70e9: 194.43 MiB / 195.64 MiB [===========================]
Copying blob 129b697f70e9: 195.64 MiB / 195.64 MiB [========================] 6s
Copying blob 129b697f70e9: 195.64 MiB / 195.64 MiB [========================] 6s
Copying blob a39553b46393: 177.41 MiB / 177.41 MiB [========================] 6s
Copying config 73f5fb57a402: 3.98 KiB / 3.98 KiB [==========================] 0s
Writing manifest to image destination
Storing signatures


导入一个镜像文件到本地仓库   -i  input
[root@node4 ~]# podman image load -i centos_7_base
Getting image source signatures
Copying blob 129b697f70e9: 183.88 MiB / 195.64 MiB [=========================>-]
Copying blob a39553b46393: 171.16 MiB / 177.41 MiB [===========================]
Copying blob 129b697f70e9: 195.64 MiB / 195.64 MiB [========================] 4s
Copying blob a39553b46393: 177.41 MiB / 177.41 MiB [========================] 4s
Copying config 73f5fb57a402: 3.98 KiB / 3.98 KiB [==========================] 0s
Writing manifest to image destination
Storing signatures
Loaded image(s): docker.io/blacklabelops/centos:latest


删除未使用的镜像
[root@node4 ~]# podman image prune --all
2d42f6c756bc02640bbb77319b5f1b3a2c51f70fd64d4919d8eb5c0d078c87a7
b9e394903cd716d89ca1fb6758bfa08dd6ec6a5966fa925c9cf58738062eba05
73f5fb57a402c17df1a74ddb154c4d2e2cd30c366e224d9cb6087ab9c6339d58
```

### 容器管理命令

#### 容器查看 ps

```
#显示开机容器
[root@node4 ~]# podman ps   
CONTAINER ID  IMAGE  COMMAND  CREATED  STATUS  PORTS  NAMES

#显示所有容器,包括没开机的
[root@node4 ~]# podman ps -a
CONTAINER ID  IMAGE                                    COMMAND    CREATED         STATUS                         PORTS  NAMES
344ce4a0a6b4  localhost/tyschool_centos8_1905:latest   /bin/bash  54 seconds ago  Exited (0) 50 seconds ago             ty2
78c97bb19bec  docker.io/mcnaughton/centos-base:latest  /bin/bash  3 minutes ago   Exited (0) About a minute ago         ty1
```

#### 容器创建 run

方法一:根据本地镜像创建容器

```
[root@node4 ~]# podman images
REPOSITORY                         TAG      IMAGE ID       CREATED         SIZE
localhost/tyschool_centos8_1905    latest   2d42f6c756bc   7 hours ago     1.4 GB
docker.io/blacklabelops/centos     latest   73f5fb57a402   13 months ago   391 MB
[root@node4 ~]# podman run -it -name ty2 localhost/tyschool_centos8_1905 /bin/bash

-i 开启容器交互
-t 分配一个TTY终端[假的]

拓展
--privileged  扩展容器权限
```

方法二: 容器创建的时候,优先从本地仓库找镜像,本地没有就回去远程仓库拉取到本地

```
本地仓库没有镜像
[root@node4 ~]# podman run --name ty1 -it docker.io/mcnaughton/centos-base /bin/bash
Trying to pull docker.io/mcnaughton/centos-base...Getting image source signatures
Copying blob a02a4930cb5d: 0 B / 71.68 MiB [-----------------------------------]
Copying blob a02a4930cb5d: 30.30 MiB / 71.68 MiB [============>----------------]
Copying blob a02a4930cb5d: 71.27 MiB / 71.68 MiB [=============================]
Copying blob a02a4930cb5d: 71.68 MiB / 71.68 MiB [=========================] 34s
Copying blob a02a4930cb5d: 71.68 MiB / 71.68 MiB [=========================] 34s
Copying blob f6168f316445: 23.45 MiB / 23.45 MiB [=========================] 34s
Copying blob cf55ab518523: 99.57 MiB / 99.57 MiB [=========================] 34s
Copying blob 68b1bf62d7e6: 1.19 KiB / 1.19 KiB [===========================] 34s
Copying config b9e394903cd7: 4.99 KiB / 4.99 KiB [==========================] 0s
Writing manifest to image destination
Storing signatures
```

#### 容器启动、关闭、重启、暂停、恢复

```
#启动容器  start
[root@node4 ~]# podman start ty1
ty1
查看容器开启了
[root@node4 ~]# podman ps
CONTAINER ID  IMAGE                                    COMMAND    CREATED        STATUS            PORTS  NAMES
78c97bb19bec  docker.io/mcnaughton/centos-base:latest  /bin/bash  4 minutes ago  Up 5 seconds ago         ty1


#关闭容器  stop
[root@node4 ~]# podman stop ty1
78c97bb19bec488b8bf5a6f68cdff9ecc20980b3c2c9e2d4c56a0946f539bd02
查看容器关闭了
[root@node4 ~]# podman ps
CONTAINER ID  IMAGE  COMMAND  CREATED  STATUS  PORTS  NAMES

#重启容器  restart
[root@node4 ~]# podman restart ty1
78c97bb19bec488b8bf5a6f68cdff9ecc20980b3c2c9e2d4c56a0946f539bd02
[root@node4 ~]#
[root@node4 ~]# podman ps
CONTAINER ID  IMAGE                                    COMMAND    CREATED        STATUS            PORTS  NAMES
78c97bb19bec  docker.io/mcnaughton/centos-base:latest  /bin/bash  6 minutes ago  Up 2 seconds ago         ty1


#暂停容器  pause
[root@node4 ~]# podman pause ty1
78c97bb19bec488b8bf5a6f68cdff9ecc20980b3c2c9e2d4c56a0946f539bd02
查看状态
[root@node4 ~]# podman ps -a
CONTAINER ID  IMAGE                                    COMMAND    CREATED        STATUS                    PORTS  NAMES
344ce4a0a6b4  localhost/tyschool_centos8_1905:latest   /bin/bash  4 minutes ago  Exited (0) 4 minutes ago         ty2
78c97bb19bec  docker.io/mcnaughton/centos-base:latest  /bin/bash  6 minutes ago  Paused                           ty1

#恢复暂停容器  unpause
[root@node4 ~]# podman unpause ty1
78c97bb19bec488b8bf5a6f68cdff9ecc20980b3c2c9e2d4c56a0946f539bd02
查看状态
[root@node4 ~]# podman ps
CONTAINER ID  IMAGE                                    COMMAND    CREATED        STATUS             PORTS  NAMES
78c97bb19bec  docker.io/mcnaughton/centos-base:latest  /bin/bash  6 minutes ago  Up 25 seconds ago         ty1
```

#### 容器性能查看 top

```
podman top 容器名称

[root@node4 ~]# podman top ty1
USER   PID   PPID   %CPU    ELAPSED          TTY     TIME   COMMAND
root   1     0      0.000   6m9.377354027s   pts/0   0s     /bin/bash
```

#### 容器连接 exec

```
连接一个运行容器,执行/bin/bash命令
[root@node4 ~]# podman exec -it ty1 /bin/bash
[root@78c97bb19bec /]#
```

#### 容器连接 attach

```
将一个运行容器的标准输出、标准错误输出、标准输入调到前台
[root@node4 ~]# podman attach ty1
[root@78c97bb19bec /]#
```

#### 根据容器生成镜像 export

```
[root@node4 ~]# podman export -o ty1.tar ty1

[root@node4 ~]# podman import  ty1.tar  baism:ty1
Getting image source signatures
Copying blob 854836d1c5c3: 491.28 MiB / 505.18 MiB [===========================]
Copying blob 854836d1c5c3: 505.18 MiB / 505.18 MiB [========================] 5s
Copying config 25581780c97b: 419 B / 419 B [================================] 0s
Writing manifest to image destination
Storing signatures
25581780c97b41ed62e0d6a9e41f8725cfaa93653e32adbb65369d3e527d235c



podman import  ty1.tar  baism:ty1

baism:ty1 自定义仓库的名称:标签
```

#### 打包更改过的容器为镜像 commit

```
[root@node4 ~]# podman commit ty1 baism:latest
Getting image source signatures
Skipping blob 071d8bd76517 (already present): 200.44 MiB / 200.44 MiB [=====] 0s
Skipping blob 3c8ab5053a82 (already present): 57.01 MiB / 57.01 MiB [=======] 0s
Skipping blob ba3cdff1294c (already present): 286.14 MiB / 286.14 MiB [=====] 0s
Skipping blob e25e400e5c38 (already present): 28.50 KiB / 28.50 KiB [=======] 0s
Skipping blob 071d8bd76517 (already present): 200.44 MiB / 200.44 MiB [=====] 1s
Skipping blob 071d8bd76517 (already present): 200.44 MiB / 200.44 MiB [=====] 1s
Skipping blob 3c8ab5053a82 (already present): 57.01 MiB / 57.01 MiB [=======] 1s
Skipping blob ba3cdff1294c (already present): 286.14 MiB / 286.14 MiB [=====] 1s
Skipping blob e25e400e5c38 (already present): 28.50 KiB / 28.50 KiB [=======] 1s
Copying blob 83e9209f930c: 114.44 MiB / 114.44 MiB [========================] 1s
Copying config d558217acef1: 4.08 KiB / 4.08 KiB [==========================] 0s
Writing manifest to image destination
Storing signatures
d558217acef109e465d5ce65d60de7c8619cc3c8cbbcde57e418555516ba3ec0
```
生无可恋
  在线 
灌水成绩
2168
16356
22354
主题
回帖
积分

等级头衔
UID : 79
等级 : 超级版主

积分成就
威望 : 1008 点
贡献 : 2377 点
蛋壳 : 20466 枚
在线时间 : 2801 小时
注册时间 : 2024-4-13
最后登录 : 2024-9-20

荣誉勋章

荣誉会员帅哥认证最佳新人活跃会员灌水之王实习版主推广达人宣传达人论坛元老热心会员优秀作者优秀版主超级版主部落真神

发表于 2024-6-2 14:24:29 | 查看全部 来自: 中国–上海–上海–松江区
每一天都是一个全新的开始
要么刷卡,要么投币,要么滚蛋。看什么看!公交车都坐不起,还冒充黑客帝国。
  离线 
灌水成绩
127
681
1712
主题
回帖
积分

等级头衔
UID : 94
等级 : 高级会员

积分成就
威望 : 147 点
贡献 : 742 点
蛋壳 : 326 枚
在线时间 : 178 小时
注册时间 : 2024-4-25
最后登录 : 2024-9-19

荣誉勋章

最佳新人实习版主活跃会员热心会员

发表于 2024-6-3 14:00:08 | 查看全部 来自: 中国–上海–上海–静安区
你只见树,未见森林
  在线 
灌水成绩
127
203
809
主题
回帖
积分

等级头衔
UID : 83
等级 : 版主

积分成就
威望 : 93 点
贡献 : 381 点
蛋壳 : 5736 枚
在线时间 : 1311 小时
注册时间 : 2024-4-17
最后登录 : 2024-9-20

荣誉勋章
 楼主| 发表于 2024-6-3 14:13:25 | 查看全部 来自: 中国–黑龙江–七台河
无法入眠的凌晨两点,烦躁就像在敲门。
生无可恋
  在线 
灌水成绩
127
203
809
主题
回帖
积分

等级头衔
UID : 83
等级 : 版主

积分成就
威望 : 93 点
贡献 : 381 点
蛋壳 : 5736 枚
在线时间 : 1311 小时
注册时间 : 2024-4-17
最后登录 : 2024-9-20

荣誉勋章
 楼主| 发表于 2024-6-3 14:13:29 | 查看全部 来自: 中国–黑龙江–七台河
活着的意义并不大,但不活着就没有意义。
生无可恋
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

1楼
2楼
3楼
4楼
5楼
投诉/建议联系

8641340@qq.com

欢迎各位朋友加入本社区,
共同维护良好的社区氛围
  • QQ用户交流群
  • 钉钉新帖推送群
Powered by Discuz! X3.5 Licensed  Copyright © 2001-2024 荷包蛋部落 版权所有 All Rights Reserved. 鲁ICP备20023396号-6
关灯 在本版发帖
加入钉钉新帖推送群
QQ客服返回顶部
快速回复 返回顶部 返回列表