podman的常用指令

podman的常用指令

podman generate

[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 web
80/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  -- / --     82          87.220863ms  0.00%

查看podman全部资源使用情况

[root@slave1 ~]# podman system df
TYPE           TOTAL       ACTIVE      SIZE        RECLAIMABLE
Images         5           2           402.7MB     228.3MB (0%)
Containers     3           2           28B         14B (0%)
Local Volumes  1           1           0B          0B (0%)

查看容器使用的所有进程

[root@slave1 ~]# podman top web1
USER        PID         PPID        %CPU        ELAPSED          TTY         TIME        COMMAND
root        1           0           0.000       7m23.157911645s  ?           0s          httpd -DFOREGROUND 
www-data    8           1           0.000       7m23.157972613s  ?           0s          httpd -DFOREGROUND 
www-data    9           1           0.000       7m23.158010966s  ?           0s          httpd -DFOREGROUND 
www-data    10          1           0.000       7m23.158059811s  ?           0s          httpd -DFOREGROUND

卸载容器的文件系统(谨慎使用)

[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 mount web1
/var/lib/containers/storage/overlay/e1f5f028cedbd1a199c50fb8981b3073b76dc084ddc6a9f3379e891c29a14715/merged
[root@slave1 ~]# podman exec -it web1 /bin/bash
root@5203a8775b21:/usr/local/apache2# 

查看podman的版本号信息

[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
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值