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-tools meta-package is installed.
  • The container is running.

Procedure

  1. Execute the rpm -qa command inside the my-support-tools container 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
    ...
  2. Execute a /bin/bash command in the my-support-tools container:

    $ podman exec -it my-support-tools /bin/bash
  3. Install the procps-ng package containing a set of system utilities (for example ps, top, uptime, and so on):

    # dnf install procps-ng
  4. Inspect 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 -ef
    • To 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_64
    • To 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
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2026 Red Hat
返回顶部