5.11. Executing commands inside a running container
Use the podman exec command to execute a command in a running container and investigate that container. The reason for using the podman exec command instead of podman run command is that you can investigate the running container without interrupting the container activity.
Prerequisites
-
The
container-toolsmeta-package is installed. - The container is running.
Procedure
Execute the
rpm -qacommand inside themy-support-toolscontainer to list all installed packages:$ 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 ...Execute a
/bin/bashcommand in themy-support-toolscontainer:$ podman exec -it my-support-tools /bin/bashInstall the
procps-ngpackage containing a set of system utilities (for exampleps,top,uptime, and so on):# dnf install procps-ngInspect the container:
To list every process on the system:
# 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 -efTo display file system disk space usage:
# 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 ...To display system information:
# uname -r 6.13.4-200.fc41.x86_64To display amount of free and used memory in megabytes:
# free --mega total used free shared buff/cache available Mem: 2818 615 1183 12 1020 1957 Swap: 3124 0 3124