5.11. 在运行中的容器中执行命令
要在正在运行的容器中运行命令并调查该容器,您可以使用 podman exec 命令。使用 podman exec 命令而不是 podman run 命令的原因是,您可以在不中断容器活动的情况下调查正在运行的容器。
先决条件
-
container-tools元数据包已安装。 - 容器正在运行。
流程
在
my-support-tools容器内输入rpm -qa命令来列出所有安装的软件包:$ podman exec -it my-support-tools rpm -qa gpg-pubkey-fd431d51-4ae0493b gpg-pubkey-5a6340b3-6229229e libgcc-11.5.0-2.el9.x86_64 setup-2.13.7-10.el9.noarch ...在
my-support-tools容器中输入/bin/bash命令:$ podman exec -it my-support-tools /bin/bash安装
procps-ng软件包,其包含一组系统工具(如ps、top和uptime,等等):# dnf install procps-ng检查容器:
要列出系统上的每个进程:
# ps -ef UID PID PPID C STIME TTY TIME CMD root 8 0 0 11:07 pts/0 00:00:00 /bin/bash root 47 8 0 11:13 pts/0 00:00:00 ps -ef要显示文件系统磁盘空间使用情况:
# df -h Filesystem Size Used Avail Use% Mounted on tmpfs 6.3G 448K 6.3G 1% /etc/hosts shm 63M 0 63M 0% /dev/shm overlay 953G 76G 877G 8% / tmpfs 64M 0 64M 0% /dev devtmpfs 4.0M 0 4.0M 0% /dev/tty ...要显示系统信息:
# uname -r 6.12.0-124.15.1.el10_1.x86_64要以 MB 为单位显示空闲和使用的内存量:
# free --mega total used free shared buff/cache available Mem: 2818 615 1183 12 1020 1957 Swap: 3124 0 3124