Podman

目录

Podman简述

Podman工作机制

Podman安装

配置加速器,以及镜像仓库

Podman常用命令

container容器管理命令

Podman简述

Podman 是一个开源项目,可在大多数 Linux 平台上使用,并位于GitHub 上。Podman 是一个无守护进程的容器引擎,用于在 Linux 系统上开发、管理和运行 Open Container Initiative (OCI) 容器和容器映像。Podman 提供了一个与 Docker 兼容的命令行前端,它可以简单地为 Docker cli ,alias docker=podman。Podman 还提供了一个套接字激活的 REST API 服务,以允许远程应用程序启动按需容器。此 REST API 还支持 Docker API,允许 docker-py 和 docker-compose 的用户与 Podman 作为服务进行交互。

Podman 控制下的容器可以由 root 或非特权用户运行。Podman 使用libpod库管理整个容器生态系统,包括 pod、容器、容器映像和容器卷。Podman 专注于帮助您维护和修改 OCI 容器镜像的所有命令和功能,例如拉取和标记。它允许您在生产环境中创建、运行和维护从这些映像创建的容器。

Podman 服务仅在 Linux 平台上运行,但 podman 远程 REST API 客户端存在于 Mac 和 Windows 平台上,并且可以通过 ssh 与运行在 Linux 机器或 VM 上的 Podman 服务进行通信。Mac 客户端。

Podman工作机制

Podman 原来是 CRI-O 项目的一部分,后来被分离成一个单独的项目叫 libpod。Podman 的使用体验和 Docker 类似,不同的是 Podman 没有 daemon。以前使用 Docker CLI 的时候,Docker CLI 会通过 gRPC API 去跟 Docker Engine 说「我要启动一个容器」,然后 Docker Engine 才会通过 OCI Container runtime(默认是 runc)来启动一个容器。这就意味着容器的进程不可能是 Docker CLI 的子进程,而是 Docker Engine 的子进程。

Podman 比较简单粗暴,它不使用 Daemon,而是直接通过 OCI runtime(默认也是 runc)来启动容器,所以容器的进程是 podman 的子进程。这比较像 Linux 的 fork/exec 模型,而 Docker 采用的是 C/S(客户端/服务器)模型。与 C/S 模型相比,fork/exec 模型有很多优势。

Podman安装

[root@localhost ~]# yum -y install podman
Failed to set locale, defaulting to C.UTF-8
CentOS Stream 8 - AppStream                          7.8 kB/s | 4.4 kB     00:00    
CentOS Stream 8 - BaseOS                             6.6 kB/s | 3.9 kB     00:00    
CentOS Stream 8 - Extras                             5.4 kB/s | 2.9 kB     00:00    
Dependencies resolved.
=====================================================================================
 Package              Arch   Version                                 Repo       Size
=====================================================================================
Installing:
 podman               x86_64 2:4.0.2-1.module_el8.7.0+1106+45480ee0  appstream  13 M
.......
python3-setools-4.3.0-3.el8.x86_64                                                 
  runc-1.0.2-1.module_el8.6.0+926+8bef8ae7.x86_64                                    
  shadow-utils-subid-2:4.6-17.el8.x86_64                                             
  slirp4netns-1.1.8-2.module_el8.7.0+1106+45480ee0.x86_64                            

Complete!

配置加速器,以及镜像仓库

[root@localhost ~]# vim /etc/containers/registries.conf   
复制下面的删除其余的镜像仓库,就留docker.io的镜像仓库
unqualified-search-registries = ["docker.io"]  
#unqualified-search-registries = ["registry.fedoraproject.org", "registry.access.redhat.com", "registry.centos.org", "docker.io"]

配置加速器
[[registry]]
prefix = "docker.io"
location = "docker.mirrors.ustc.edu.cn"   配置清华大学加速器

Podman常用命令

[root@localhost ~]# podman search  httpd                               //检索镜像
INDEX       NAME                                             DESCRIPTION             
                         STARS       OFFICIAL    AUTOMATED
docker.io   docker.io/library/httpd                          The Apache HTTP Server P
roject                   4116        [OK]        
docker.io   docker.io/clearlinux/httpd                       httpd HyperText Transfer
 Protocol (HTTP) ser...  2                       
.......
docker.io   docker.io/jonathanheilmann/httpd-alpine-rewrite  httpd:alpine with enabled mod_rewrite            1                       [OK]
docker.io   docker.io/sandeep1988/httpd-new                  httpd-new                                        0                       

[root@localhost ~]# podman pull httpd                                  //获取镜像
Trying to pull docker.io/library/httpd:latest...
Getting image source signatures
.....
Storing signatures
dabbfbe0c57b6e5cd4bc089818d3f664acfad496dc741c9a501e72d15e803b34

[root@localhost ~]# podman images                                      //列出镜像 
REPOSITORY               TAG         IMAGE ID      CREATED       SIZE
docker.io/library/httpd  latest      dabbfbe0c57b  7 months ago  148 MB
           
[root@localhost ~]# podman image save httpd > http.tar                 //导出镜像
[root@localhost ~]# ls
anaconda-ks.cfg  http.tar

[root@localhost ~]# podman load < http.tar                             //导入镜像
Getting image source signatures
Copying blob deefaa620a71 skipped: already exists  
........
Storing signatures
Loaded image(s): docker.io/library/httpd:latest

[root@localhost ~]# podman rmi httpd                                   //删除镜像
Untagged: docker.io/library/httpd:latest
Deleted: dabbfbe0c57b6e5cd4bc089818d3f664acfad496dc741c9a501e72d15e803b34

container容器管理命令

[root@localhost ~]# podman container create --name wq httpd           //创建并启动容器 
8b95b6d21d1d785d88f8a32fc93f98ad37574c5e5c3fcc3eee91cb97a0a61e27

[root@localhost ~]#  podman start wq                                  //启动容器
wq

[root@localhost ~]# podman ps                                         //查看容器
CONTAINER ID  IMAGE                           COMMAND           CREATED         STATUS             PORTS       NAMES
8b95b6d21d1d  docker.io/library/httpd:latest  httpd-foreground  27 seconds ago  Up 10 seconds ago              wq

[root@localhost ~]# podman stop wq                                    //终止容器
wq

[root@localhost ~]# podman restart wq                                 //重启容器
8b95b6d21d1d785d88f8a32fc93f98ad37574c5e5c3fcc3eee91cb97a0a61e27

[root@localhost ~]# podman attach wq                              //连接到运行的容器
/ # 

[root@localhost ~]# podman exec -it  wq /bin/sh          //在正在运行的容器中运行进程
/ # 

[root@localhost ~]# podman export > /root/wq.tar  wq                  //导出容器
[root@localhost ~]# ls
wq.tar

[root@localhost ~]# podman rm -f wq                                   //删除容器
8b95b6d21d1d785d88f8a32fc93f98ad37574c5e5c3fcc3eee91cb97a0a61e27

[root@localhost ~]# podman logs wq                                    //查看日志

[root@localhost ~]# podman container logs wq
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 10.88.0.6. Set the 'ServerName' directive globally to suppress this message

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值