使用 Podman
使用 Podman 非常的简单,Podman 的指令跟 Docker 大多数都是相同的。下面我们来看几个常用的例子:
运行一个容器
podman run d –name httpd docker.io/library/httpd //运行一个容器
[root@localhost ~]# podman run -d --name httpd docker.io/library/httpd
Trying to pull docker.io/library/httpd:latest...
Getting image source signatures
Copying blob 1efc276f4ff9 done
Copying blob aed046121ed8 done
Copying blob 80e368ef21fc done
Copying blob 4340e7be3d7f done
Copying blob 80cb79a80bbe done
Copying config f2a976f932 done
Writing manifest to image destination
Storing signatures
87c8f6d682da1bc768ec923f5ffc938880da80369685c0ab56f4b28f6790d5da
[root@localhost ~]#
查看镜像
docker.io/library/httpd latest f2a976f932ec 13 days ago 149 MB
podman ps //列出运行的容器
[root@localhost ~]# podman ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
87c8f6d682da docker.io/library/httpd:latest httpd-foreground 3 minutes ago Up 3 minutes ago httpd
[root@localhost ~]#
注意:如果在ps命令中添加-a,Podman 将显示所有容器。
检查正在运行的容器
您可以“检查”正在运行的容器的元数据和有关其自身的详细信息。我们甚至可以使用 inspect 子命令查看分配给容器的 IP 地址。由于容器以无根模式运行,因此未分配 IP 地址,并且该值将在检查的输出中列为“无”。
podman inspect l| grep i address //使用 inspect 子命令查看分配给容器的 IP 地址
[root@localhost ~]# podman inspect -l| grep -i address
"IPAddress": "10.88.0.2",
"GlobalIPv6Address": "",
"MacAddress": "c6:22:60:ac:e3:67",
"LinkLocalIPv6Address": "",
"IPAddress": "10.88.0.2",
"GlobalIPv6Address": "",
"MacAddress": "c6:22:60:ac:e3:67",
[root@localhost ~]# curl 10.88.0.2
<html><body><h1>It works!</h1></body></html>
[root@localhost ~]#
注意:-l 是最新容器的便利参数。您还可以使用容器的 ID 代替 -l。
查看一个运行中容器的日志
选项
--latest #最近的
[root@localhost ~]# podman logs --latest
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 10.88.0.2. 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.2. Set the 'ServerName' directive globally to suppress this message
[Mon Aug 15 12:00:01.088281 2022] [mpm_event:notice] [pid 1:tid 140034235927872] AH00489: Apache/2.4.54 (Unix) configured -- resuming normal operations
[Mon Aug 15 12:00:01.088617 2022] [core:notice] [pid 1:tid 140034235927872] AH00094: Command line: 'httpd -D FOREGROUND'
10.88.0.1 - - [15/Aug/2022:12:05:28 +0000] "GET / HTTP/1.1" 200 45
[root@localhost ~]#
查看一个运行容器中的进程资源使用情况,可以使用top观察容器中的 nginx pid
语法:
[root@localhost ~]# podman top httpd
USER PID PPID %CPU ELAPSED TTY TIME COMMAND
root 1 0 0.000 8m52.932781729s ? 0s httpd -DFOREGROUND
www-data 7 1 0.000 8m52.932905865s ? 0s httpd -DFOREGROUND
www-data 8 1 0.000 8m52.932993084s ? 0s httpd -DFOREGROUND
www-data 9 1 0.000 8m52.933076665s ? 0s httpd -DFOREGROUND
[root@localhost ~]#
<