podman
使用 Podman
使用 Podman 非常的简单,Podman 的指令跟 Docker 大多数都是相同的。下面我们来看几个常用的例子:
运行一个容器
[root@localhost ~]# podman run -d --name web1 httpd
Resolving "httpd" using unqualified-search registries (/etc/containers/registrie
Trying to pull docker.io/library/httpd:latest...
Getting image source signatures
Copying blob 1efc276f4ff9 done
Copying blob 80cb79a80bbe done
Copying blob 4340e7be3d7f done
Copying blob aed046121ed8 done
Copying blob 80e368ef21fc done
Copying config f2a976f932 done
Writing manifest to image destination
Storing signatures
8e87d33fedaef42db358db3d2152aaa9de16cd7e51016cef48a0e01d9fd730db
//查看镜像
[root@localhost ~]# podman images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/library/httpd latest f2a976f932ec 13 days ago 149 MB
docker.io/wyn0116/busybox123 v1 7a80323521cc 2 weeks ago 1.47 MB
docker.io/library/busybox latest 7a80323521cc 2 weeks ago 1.47 MB
列出运行的容器
[root@localhost ~]# podman ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6229a94b2a49 docker.io/library/busybox:latest sh 22 hours ago Up 22 hours ago yyz
8e87d33fedae docker.io/library/httpd:latest httpd-foreground 2 minutes ago Up 2 minutes ago web1
[root@localhost ~]# podman ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6229a94b2a49 docker.io/library/busybox:latest sh 22 hours ago Up 22 hours ago yyz
8e87d33fedae docker.io/library/httpd:latest httpd-foreground 3 minutes ago Up 3 minutes ago web1
注意:如果在ps命令中添加-a,Podman 将显示所有容器。
检查正在运行的容器
您可以“检查”正在运行的容器的元数据和有关其自身的详细信息。我们甚至可以使用 inspect 子命令查看分配给容器的 IP 地址。由于容器以无根模式运行,因此未分配 IP 地址,并且该值将在检查的输出中列为“无”。
[root@localhost ~]# podman inspect -l | grep IPAddress\":
"IPAddress": "10.88.0.5",
"IPAddress": "10.88.0.5",
[root@localhost ~]# curl 10.88.0.5
<html><body><h1>It works!</h1></body></html>
注意:-l 是最新容器的便利参数。您还可以使用容器的 ID 代替 -l。
查看一个运行中容器的日志
选项
–latest #最近的
[root@localhost ~]# podman logs -l
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 10.88.0.5. 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.5. Set the 'ServerName' directive globally to suppress this message
[Mon Aug 15 07:35:13.377854 2022] [mpm_event:notice] [pid 1:tid 139753627139392] AH00489: Apache/2.4.54 (Unix) configured -- resuming normal operations
[Mon Aug 15 07:35:13.378237 2022] [core:notice] [pid 1:tid 139753627139392] AH00094: Command line: 'httpd -D FOREGROUND'
10.88.0.1 - - [15/Aug/2022:07:41:04 +0000] "GET / HTTP/1.1" 200 45
查看一个运行容器中的进程资源使用情况,可以使用top观察容器中的 nginx pid
语法:
podman top <container_id>
[root@localhost ~]# podman top 8e87d33fedae
USER PID PPID %CPU ELAPSED TTY TIME COMMAND
root 1 0 0.000 20m41.189593645s ? 0s httpd -DFOREGROUND
www-data 7 1 0.000 20m40.189786642s ? 0s httpd -DFOREGROUND
www-data 8 1 0.000 20m40.189931624s ? 0s httpd -DFOREGROUND
www-data 9 1 0.000 20m40.190205558s ? 0s httpd -DFOREGROUND