podman的配置以及命令详解
podman
- podman简介
- Podman和Docker的区别
- Podman的使用与docker使用的区别
- Podman常用命令
- 部署 Podman以及配置加速器
- podman基础命令详解(部分)
podman简介
Podman 是一个开源的容器运行时项目,可在大多数 Linux 平台上使用。Podman 提供与 Docker 非常相似的功能。正如前面提到的那样,它不需要在你的系统上运行任何守护进程,并且它也可以在没有 root 权限的情况下运行。
Podman 可以管理和运行任何符合 OCI(Open Container Initiative)规范的容器和容器镜像。Podman 提供了一个与 Docker 兼容的命令行前端来管理 Docker 镜像。
Podman 官网地址
Podman和Docker的区别
- dockers在实现CRI的时候,它需要一个守护进程,其次需要以root运行,因此这也带来了安全隐患。
- podman不需要守护程序,也不需要root用户运行,从逻辑架构上,比docker更加合理。
- 在docker的运行体系中,需要多个daemon才能调用到OCI的实现RunC。
- 在容器管理的链路中,Docker Engine的实现就是dockerd
- daemon,它在linux中需要以root运行,dockerd调用containerd,containerd调用containerd-shim,然后才能调用runC。顾名思义shim起的作用也就是“垫片”,避免父进程退出影响容器的运训
- podman直接调用OCI,runtime(runC),通过common作为容器进程的管理工具,但不需要dockerd这种以root身份运行的守护进程。
- 在podman体系中,有个称之为common的守护进程,其运行路径通常- 是/usr/libexec/podman/conmon,它是各个容器进程的父进程,每个容器各有一个,common的父则通常是1号进程。podman中的common其实相当于docker体系中的containerd-shim。
图中所体现的事情是,podman不需要守护进程,而dorker需要守护进程。在这个图的示意中,dorcker的containerd-shim与podman的common被归在Container一层。
Podman的使用与docker使用的区别
podman的定位也是与docker兼容,因此在使用上面尽量靠近docker。在使用方面,可以分成两个方面来说,一是系统构建者的角度,二是使用者的角度。
在系统构建者方面,用podman的默认软件,与docker的区别不大,只是在进程模型、进程关系方面有所区别。如果习惯了docker几个关联进程的调试方法,在podman中则需要适应。可以通过pstree命令查看进程的树状结构。总体来看,podman比docker要简单。由于podman比docker少了一层daemon,因此重启的机制也就不同了。
在使用者方面,podman与docker的命令基本兼容,都包括容器运行时(run/start/kill/ps/inspect),本地镜像(images/rmi/build)、镜像仓库(login/pull/push)等几个方面。因此podman的命令行工具与docker类似,比如构建镜像、启停容器等。甚至可以通过alias
docker=podman可以进行替换。因此,即便使用了podman,仍然可以使用http://docker.io作为镜像仓库,这也是兼容性最关键的部分。
Podman常用命令
容器
命令 | 用法 |
---|---|
podman run | 创建并启动容器 |
podman start | 启动容器 |
podman ps | 查看容器 |
podman stop | 终止容器 |
podman restart | 重启容器 |
podman attach | 进入容器 |
podman exec | 进入容器 |
podman export | 导出容器 |
podman import | 导入容器快照 |
podman rm | 删除容器 |
podman logs | 查看日志 |
镜像 | |
podman search | 检索镜像 |
podman pull | 获取镜像 |
podman images | 列出镜像 |
podman image Is | 列出镜像 |
podman rmi | 删除镜像 |
podman image rm | 删除镜像 |
podman save | 导出镜像 |
podman load | 导入镜像 |
podmanfile | 定制镜像(三个) |
podman build | 构建镜像 |
podman run | 运行镜像 |
podmanfile | 常用指令(四个) |
---|---|
COPY | 复制文件 |
ADD | 高级复制 |
CMD | 容器启动命令 |
ENV | 环境变量 |
EXPOSE | 暴露端口 |
部署 Podman以及配置加速器
配置yum源
[root@localhost yum.repos.d]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# rm -rf *
[root@localhost yum.repos.d]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
--2022-08-13 23:44:03-- https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
正在解析主机 mirrors.aliyun.com (mirrors.aliyun.com)... 223.76.171.230, 223.76.170.224, 223.76.171.227, ...
正在连接 mirrors.aliyun.com (mirrors.aliyun.com)|223.76.171.230|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:2495 (2.4K) [application/octet-stream]
正在保存至: “/etc/yum.repos.d/CentOS-Base.repo”/etc/yum.repos.d/CentOS 100%[============================>] 2.44K --.-KB/s 用时 0s 2022-08-13 23:44:03 (21.7 MB/s) - 已保存 “/etc/yum.repos.d/CentOS-Base.repo” [2495/2495])[root@localhost yum.repos.d]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
下载podman
[root@localhost ~]# dnf -y install podman
配置加速器
[root@localhost ~]# vim /etc/containers/registries.conf
unqualified-search-registries = ["docker.io"]
[[registry]]
location = "glvnpwyn.mirror.aliyuncs.com"
拉镜像
[root@localhost ~]# podman pull busybox
Resolved "busybox" as an alias (/etc/containers/registries.conf.d/000-shortnames.conf)
Trying to pull docker.io/library/busybox:latest...
Getting image source signatures
Copying blob 50783e0dfb64 done
Copying config 7a80323521 done
Writing manifest to image destination
Storing signatures
7a80323521ccd4c2b4b423fa6e38e5cea156600f40cd855e464cc52a321a24dd
[root@localhost ~]# podman images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/library/busybox latest 7a80323521cc 2 weeks ago 1.47 MB
[root@localhost ~]#
改标签
[root@localhost ~]# podman tag docker.io/library/busybox:latest docker.io/hzsjxx/busybox:v5
[root@localhost ~]# podman images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/library/busybox latest 7a80323521cc 2 weeks ago 1.47 MB
docker.io/hzsjxx/busybox v5 7a80323521cc 2 weeks ago 1.47 MB
认证
[root@localhost ~]# podman login docker.io
Username: hzsjxx
Password:
Login Succeeded!
[root@localhost ~]#
上传镜像
[root@localhost ~]# podman push docker.io/hzsjxx/busybox:v5
Getting image source signatures
Copying blob 084326605ab6 skipped: already exists
Copying config 7a80323521 done
Writing manifest to image destination
Storing signatures
在拉取刚上传镜像
[root@localhost ~]# podman images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/hzsjxx/busybox v5 7a80323521cc 2 weeks ago 1.47 MB
docker.io/library/busybox latest 7a80323521cc 2 weeks ago 1.47 MB
docker.io/hzsjxx/busybox v8 7a80323521cc 2 weeks ago 1.47 MB
[root@localhost ~]# podman rmi docker.io/hzsjxx/busybox:v5
Untagged: docker.io/hzsjxx/busybox:v5
[root@localhost ~]# podman images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/library/busybox latest 7a80323521cc 2 weeks ago 1.47 MB
docker.io/hzsjxx/busybox v8 7a80323521cc 2 weeks ago 1.47 MB
[root@localhost ~]# podman pull hzsjxx/busybox:v5
Resolving "hzsjxx/busybox" using unqualified-search registries (/etc/containers/registries.conf)
Trying to pull docker.io/hzsjxx/busybox:v5...
Getting image source signatures
Copying blob 50783e0dfb64 skipped: already exists
Copying config 7a80323521 done
Writing manifest to image destination
Storing signatures
7a80323521ccd4c2b4b423fa6e38e5cea156600f40cd855e464cc52a321a24dd
[root@localhost ~]# podman images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/hzsjxx/busybox v5 7a80323521cc 2 weeks ago 1.47 MB
docker.io/library/busybox latest 7a80323521cc 2 weeks ago 1.47 MB
docker.io/hzsjxx/busybox v8 7a80323521cc 2 weeks ago 1.47 MB
[root@localhost ~]#
podman基础命令详解(部分)
podman的使用
[root@localhost ~]# podman search busybox //搜索busybox镜像,默认到docker官方的镜像仓库去找
INDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATED
docker.io docker.io/library/busybox Busybox base image. 2415 [OK]
docker.io docker.io/radial/busyboxplus Full-chain, Internet enabled, busybox made f... 43 [OK]
docker.io docker.io/yauritux/busybox-curl Busybox with CURL 16
docker.io docker.io/arm64v8/busybox Busybox base image. 3
docker.io docker.io/vukomir/busybox busybox and curl 1
docker.io docker.io/amd64/busybox Busybox base image. 0
docker.io docker.io/odise/busybox-curl 4 [OK]
docker.io docker.io/ppc64le/busybox Busybox base image. 1
docker.io docker.io/arm32v7/busybox Busybox base image. 10
docker.io docker.io/s390x/busybox Busybox base image. 2
docker.io docker.io/prom/busybox Prometheus Busybox Docker base images 2 [OK]
docker.io docker.io/i386/busybox Busybox base image. 2
docker.io docker.io/joeshaw/busybox-nonroot Busybox container with non-root user nobody 2
docker.io docker.io/p7ppc64/busybox Busybox base image for ppc64. 2
docker.io docker.io/arm32v6/busybox Busybox base image. 3
docker.io docker.io/arm32v5/busybox Busybox base image. 0
docker.io docker.io/armhf/busybox Busybox base image. 6
docker.io docker.io/mips64le/busybox Busybox base image. 1
docker.io docker.io/spotify/busybox Spotify fork of https://hub.docker.com/_/bus... 1
docker.io docker.io/aarch64/busybox Busybox base image. 3
docker.io docker.io/progrium/busybox 70 [OK]
docker.io docker.io/lqshow/busybox-curl Busybox image adds a curl binary to /usr/bin 1 [OK]
docker.io docker.io/ggtools/busybox-ubuntu Busybox ubuntu version with extra goodies 0 [OK]
docker.io docker.io/odise/busybox-python 4 [OK]// 运行 busybox 容器镜像[root@localhost ~]# podman run -it docker.io/library/busybox
Trying to pull docker.io/library/busybox:latest...
Getting image source signatures
Copying blob 3cb635b06aa2 done
Copying config ffe9d497c3 done
Writing manifest to image destination
Storing signatures
/ # ls
bin dev etc home proc root run sys tmp usr var// 查看指定镜像的详细信息[root@localhost files]# podman inspect nginx
.... "PATH=/usr/local/nginx/sbin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"],"Cmd": ["nginx","-g","daemon off"],
省略N行// 查看容器的详细信息
[root@localhost nginx]# podman inspect nginx
[{"Id": "65482769724a6cd5c858b4d96456d01a4101d9da7818139482c6b6cc1fa9c2f5","Created": "2021-12-14T10:20:42.249764947+08:00","Path": "/docker-entrypoint.sh","Args": ["nginx","-g","daemon off;""NetworkSettings": {"EndpointID": "","Gateway": "10.88.0.1", "IPAddress": "10.88.0.5", //容器的IP地址"IPPrefixLen": 16,"IPv6Gateway": "",// 通过IP地址访问容器
[root@localhost ~]# curl 10.88.0.5
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p><p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p><p><em>Thank you for using nginx.</em></p>
</body>
</html>// 查看某个容器的访问日志[root@localhost ~]# podman logs --latest // 默认使最近的一个容器的访文信息
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
2022/08/14 12:20:42 [notice] 1#1: using the "epoll" event method
2022/08/14 12:20:42 [notice] 1#1: nginx/1.21.4
2022/08/14 12:20:42 [notice] 1#1: built by gcc 10.2.1 20210110 (Debian 10.2.1-6)
2022/08/14 12:20:42 [notice] 1#1: OS: Linux 4.18.0-257.el8.x86_64
2022/08/14 12:20:42 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576
2022/08/14 12:20:42 [notice] 1#1: start worker processes
2022/08/14 12:20:42 [notice] 1#1: start worker process 30
2022/08/14 12:20:42 [notice] 1#1: start worker process 31
10.88.0.1 - - [14/Dec/2022:08:14 12:20:42 +0000] "GET / HTTP/1.1" 200 615 "-" "curl/7.61.1" "-"// 运行容器测试访问信息[root@localhost ~]# podman run -d --name web docker.io/library/httpd
Trying to pull docker.io/library/httpd:latest...
Getting image source signatures
Copying blob e5ae68f74026 skipped: already exists
Copying blob bc36ee1127ec done
Copying blob f1aa5f54b226 done
Copying blob d3576f2b6317 done
Copying blob aa379c0cedc2 done
Copying config ea28e1b82f done
Writing manifest to image destination
Storing signatures
9edf15ce189f0694129b6f30e96f265540698b33a34bf566e7488c839d813038
// 运行一个apache容器
[root@localhost ~]# podman run -d --name web docker.io/library/httpd[root@localhost ~]# podman inspect web //查看详细信息"Mounts": [],"Dependencies": [],"NetworkSettings": {"EndpointID": "","Gateway": "10.88.0.1","IPAddress": "10.88.0.6",[root@localhost ~]# curl 10.88.0.6
<html><body><h1>It works!</h1></body></html>// 访问两次apache
[root@localhost ~]# curl 10.88.0.6
<html><body><h1>It works!</h1></body></html>
[root@localhost ~]# curl 10.88.0.6
<html><body><h1>It works!</h1></body></html>// 默认查看最新的一个容器的访问日志
[root@localhost ~]# podman logs --latest
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
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
[Tue Dec 14 12:20:42.797618 2022] [mpm_event:notice] [pid 1:tid 139840743701824] AH00489: Apache/2.4.51 (Unix) configured -- resuming normal operations
[Tue Dec 14 12:20:42.798545 2022] [core:notice] [pid 1:tid 139840743701824] AH00094: Command line: 'httpd -D FOREGROUND'
10.88.0.1 - - [14/Dec/2022/08/14 12:19:42 +0000] "GET / HTTP/1.1" 200 45
10.88.0.1 - - [14/Dec/2022/08/14 12:20:42 +0000] "GET / HTTP/1.1" 200 45// 查看指定容器的访问信息[root@localhost ~]# podman logs nginx //可以通过容器的名称或id进行查看
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
2022/08/14 12:20:42 [notice] 1#1: using the "epoll" event method
2022/08/14 12:20:42 [notice] 1#1: nginx/1.21.4
2022/08/14 12:20:42 [notice] 1#1: built by gcc 10.2.1 20210110 (Debian 10.2.1-6)
2022/08/14 12:20:42 [notice] 1#1: OS: Linux 4.18.0-257.el8.x86_64
2022/08/14 12:20:42 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576
2022/08/14 12:20:42 [notice] 1#1: start worker processes
2022/08/14 12:20:42 [notice] 1#1: start worker process 30
2022/08/14 12:20:42 [notice] 1#1: start worker process 31
10.88.0.1 - - [14/Dec/2022/08/14 12:20:42 +0000] "GET / HTTP/1.1" 200 615 "-" "curl/7.61.1" "-"// 查看指定容器的进程信息[root@localhost ~]# podman top nginx
USER PID PPID %CPU ELAPSED TTY TIME COMMAND
root 1 0 0.000 1h31m9.485762974s ? 0s nginx: master process nginx -g daemon off;
nginx 30 1 0.000 1h31m9.486477743s ? 0s nginx: worker process
nginx 31 1 0.000 1h31m9.486828771s ? 0s nginx: worker process
// 容器的备份与恢复注意此功能只有管理员才可以使用
// 若此命令使用不了请安装 criu3.11版本
[root@localhost ~]# podman container checkpoint web // 备份
698566e7488c839d8954edf14120b0e96f2633a34bf130389b65ce189f069f3
[root@localhost ~]# podman container restore web // 恢复
698566e7488c839d8954edf14120b0e96f2633a34bf130389b65ce189f069f3
// 容器的停止与启动[root@localhost ~]# podman stop web //这个使停止指定的容器
[root@localhost ~]# podman stop --latest //停止最新的一个容器
[root@localhost ~]# podman ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6818139482c6 docker.io/library/nginx:latest nginx -g daemon o... 2 hours ago Up 2 hours ago nginx
54edf15ce189 docker.io/library/httpd:latest httpd-foreground 26 minutes ago Up 26 minutes ago web[root@localhost ~]# podman stop --latest
[root@localhost ~]# podman ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6818139482c6 docker.io/library/nginx:latest nginx -g daemon o... 2 hours ago Up 2 hours ago nginx[root@localhost ~]# podman start web //启动容器
web
// 删除容器
[root@localhost ~]# podman rm nginx //删除指定的容器
[root@localhost ~]# podman rm --latest //删除最新的容器,删除之前需要先停止容器,-f可以强制删除,不需要停止容器
4bf130389b6698566e88c839d89b33a374f265f30e9654edf15ce189f0694120
podman的配置以及命令详解相关推荐
- 华为关闭telnet命令_华为s5720配置telnet命令详解
华为s5720配置telnet命令详解 以本地PC登录远程的Telnet_Server为例,Telent登录配置如下: 1. 使能服务器功能 system-view [HUAWEI] sysname ...
- maven运行时的配置及命令详解
上面是指定端口运行程序的,也可以先指定好,直接在上面的地方写jettty:run 当然,如果你是在控制台运行且安装了maven,直接可以进入项目的文件中:mvn jetty:run ...
- centos 文件夹网络连接_CentOS的网络配置的命令详解
我们在进行对CentOS的网络配置时,一般会从IP地址(IPADDR).子网掩码(NETMASK).网关(Gateway).主机名(HOSTNAME).DNS服务器等方面入手.而在CentOS中,又有 ...
- 华为、H3C、锐捷三家交换机配置命令详解
一.华为交换机基础配置命令 1.创建vlan: <Quidway> //用户视图,也就是在Quidway模式下运行命令. <Quidway>system-view //进入配置 ...
- 华为3COM交换机配置命令详解
华为3COM交换机配置命令详解 1.配置文件相关命令 [Quidway]display current-configuration ;显示当前生效的配置 [Quidway]displa ...
- 华三交换机配置access命令_h3c交换机配置命令详解
H3C 交换机配置命令详解 华为 3COM 交换机配置命令详解 1 .配置文件相关命令 [Quidway]display current-configuration ; 显示当前生效的 ...
- 华三交换机配置access命令_H3C-交换机配置命令详解
华为 3COM 交换机配置命令详解 1 .配置文件相关命令 [Quidway]display current-configuration ; 显示当前生效的配置 [Quidway]display sa ...
- H3C 交换机配置命令详解
H3C 交换机配置命令详解 华为3COM交换机配置命令详解 1.配置文件相关命令 [Quidway]display current-configuration ;显示当前生效的配置 [ ...
- 华为交换机关机方法_华为交换机启动配置命令详解大全
华为交换机启动配置命令详解大全 1.自动保存配置 [Huawei]set save-configuration ? backup-to-server Back up the configuratio ...
- 华三交换机镜像配置命令_H3C交换机配置命令详解
H3C交换机配置命令详解 1.配置文件相关命令 [Quidway]display current-configuration ;显示当前生效的配置 [Quidway]display s ...
最新文章
- win2008r2下安装sql2008r2初版
- (转)JS window对象的top、parent、opener含义
- 国王游戏(洛谷-P1080)
- 使用fstream在C++工程中读取文件到二维数组
- 【Flink】FLink 通讯组件 Akka与Actor 模型
- selenium grid原理
- 计算机科学为什么重要,数学 – 为什么在计算机科学中有8和256个如此重要的数字?...
- Effective C++ 之 Item 5:了解C++默默编写并调用哪些函数
- 我们计划招收300名深度学习者,免费攻读傅里叶变换和MATLAB
- 2020年了,Windows Me还能用吗?
- 关于VLAN的几种接口模式
- 三.	SECS/GEM封装库RapidSecs开发手记-SECS/GEM基础知识-1
- 2020中青杯B题股指与国家经济数学建模全过程文档及程序
- T检验、卡方检验、F检验
- linux7 域名解析,CentOS 7之DNS域名解析
- 软件测试肖sir__009之mysql多表(4)
- cad2020打印样式放在哪个文件夹_deepin使用笔记——Linux配置惠普(HP)打印机
- 群晖服务器无限重启,监控群晖服务状态并自动重启 | 群晖服务控制
- 6.28(HTML2)
- 《机器学习100修炼秘籍》