[root@slave1 ~]# podman run -d --name web -p 80:80 httpd
4a8f4b8d3194cbacafbc4bb709cdf87f648e1eeb108edf175bbc130edaefd76
//--name 指定容器名字 --file 创建files文件 --new 重新创建一个新容器
[root@slave1 ~]# podman generate systemd --name web --files --new
/root/container-web.service
[root@slave1 ~]# ls
all-202207282024.sql apr-1.7.0 httpd-2.4.51
anaconda-ks.cfg container-web.service
//可以将这个文件放入到/usr/lib/systemd/system ,以便用systemctl进行管理
[root@slave1 ~]# cp container-web.service /usr/lib/systemd/system[root@slave1 ~]# systemctl daemon-reload[root@slave1 ~]# systemctl status container-web.service
● container-web.service - Podman container-web.service
Loaded: loaded (/usr/lib/systemd/system/container-web.service;>
Active: inactive (dead)
Docs: man:podman-generate-systemd(1)[root@slave1 ~]# podman ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a220b1aea747 docker.io/library/registry:latest /etc/docker/regis... 2 hours ago Up 2 hours ago 0.0.0.0:5000->5000/tcp sad_lamport
4a8f4b8d3194 docker.io/library/httpd:latest httpd-foreground 5 minutes ago Up 5 minutes ago 0.0.0.0:80->80/tcp web
[root@slave1 ~]# podman rm -f 4a8f4b8d3194
4a8f4b8d3194cbacafbc4bb709cdf87f648e1eeb108edf175bbc130edaefd766
[root@slave1 ~]# podman ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a220b1aea747 docker.io/library/registry:latest /etc/docker/regis... 2 hours ago Up 2 hours ago 0.0.0.0:5000->5000/tcp sad_lamport
[root@slave1 ~]# systemctl enable --now container-web.service
Created symlink /etc/systemd/system/multi-user.target.wants/container-web.service → /usr/lib/systemd/system/container-web.service.
Created symlink /etc/systemd/system/default.target.wants/container-web.service → /usr/lib/systemd/system/container-web.service.
[root@slave1 ~]# podman ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a220b1aea747 docker.io/library/registry:latest /etc/docker/regis... 2 hours ago Up 2 hours ago 0.0.0.0:5000->5000/tcp sad_lamport
5203a8775b21 docker.io/library/httpd:latest httpd-foreground 6 seconds ago Up 6 seconds ago 0.0.0.0:80->80/tcp web
查看容器日志
[root@slave1 ~]# podman logs web
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 10.88.0.4. 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.4. Set the 'ServerName' directive globally to suppress this message
[Tue Aug 16 03:33:37.311848 2022][mpm_event:notice][pid 1:tid 139879730511168] AH00489: Apache/2.4.52 (Unix) configured -- resuming normal operations
[Tue Aug 16 03:33:37.311979 2022][core:notice][pid 1:tid 139879730511168] AH00094: Command line: 'httpd -D FOREGROUND'
查看容器映射端口
[root@slave1 ~]# podman port web80/tcp ->0.0.0.0:80
修改容器名称
[root@slave1 ~]# podman rename web web1[root@slave1 ~]# podman ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a220b1aea747 docker.io/library/registry:latest /etc/docker/regis... 2 hours ago Up 2 hours ago 0.0.0.0:5000->5000/tcp sad_lamport
5203a8775b21 docker.io/library/httpd:latest httpd-foreground 2 minutes ago Up 2 minutes ago 0.0.0.0:80->80/tcp web1
查看容器资源使用率
[root@slave1 ~]# podman stats web1
ID NAME CPU % MEM USAGE / LIMIT MEM % NET IO BLOCK IO PIDS CPU TIME AVG CPU %
5203a8775b21 web1 0.00% 31.56MB / 2.045GB 1.54% 978B / 1.424kB -- / -- 8287.220863ms 0.00%
查看podman全部资源使用情况
[root@slave1 ~]# podman system df
TYPE TOTAL ACTIVE SIZE RECLAIMABLE
Images 52402.7MB 228.3MB (0%)
Containers 32 28B 14B (0%)
Local Volumes 11 0B 0B (0%)
[root@slave1 ~]# podman unmount web1[root@slave1 ~]# podman unmount web1
web1
[root@slave1 ~]# podman exec -it web1 /bin/bash
Error: exec failed: container_linux.go:380: starting container process caused: process_linux.go:99: starting setns process caused: fork/exec /proc/self/exe: no such file or directory: OCI runtime attempted to invoke a command that was not found
[root@slave1 ~]# podman version
Version: 3.3.1
API Version: 3.3.1
Go Version: go1.16.7
Built: Wed Nov 10 05:23:56 2021
OS/Arch: linux/amd64
podman -l管理最近一次使用容器
[root@slave1 ~]# podman ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a220b1aea747 docker.io/library/registry:latest /etc/docker/regis... 2 hours ago Up 2 hours ago 0.0.0.0:5000->5000/tcp sad_lamport
5203a8775b21 docker.io/library/httpd:latest httpd-foreground 14 minutes ago Up 14 minutes ago 0.0.0.0:80->80/tcp web1
[root@slave1 ~]# podman stop -l
5203a8775b2198d6c655549fb1a9dc4bd396e4ec4c18c90fae54de09c12b2efc
[root@slave1 ~]# podman ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a220b1aea747 docker.io/library/registry:latest /etc/docker/regis... 2 hours ago Up 2 hours ago 0.0.0.0:5000->5000/tcp sad_lamport