Skip to main content

How to use Podman to get information about your containers

Use the podman ps command to get size, resource consumption, and other information about your containers.
Image
Multicolored containers at port

Mylene2401. Pixabay

Podman is a daemon-less engine for developing, managing, and running Open Container Initiative (OCI)-compliant containers. This is the second article in a series about using Podman based on things I do in my real work environment. In my previous article, I showed you how to start containers quickly and easily using the familiar interface of shell scripting.

In this article, I'll demonstrate how to get insight into running containers. If you want to follow along with this article, first run the shell scripts I used in the "Setting things up" section of the first article in this series.

Get information about running containers

The main command to print out information about the running containers is podman ps. Or, if you're running containers inside pods, podman pod ps has the same purpose. Here are the full options for these commands:

$ podman ps --help

List containers

Description:
  Prints out information about the containers

Usage:
  podman ps [options]

Examples:
  podman ps -a
  podman ps -a --format "{{.ID}}  {{.Image}}  {{.Labels}}  {{.Mounts}}"
  podman ps --size --sort names

Options:
  -a, --all              Show all the containers, default is only running containers
      --external         Show containers in storage not controlled by Podman
  -f, --filter strings   Filter output based on conditions given
      --format string    Pretty-print containers to JSON or using a Go template
  -n, --last int         Print the n last created containers (all states) (default -1)
  -l, --latest           Act on the latest container podman is aware of
                         Not supported with the "--remote" flag
      --no-trunc         Display the extended information
      --ns               Display namespace information
  -p, --pod              Print the ID and name of the pod the containers are associated with
  -q, --quiet            Print the numeric IDs of the containers only
  -s, --size             Display the total file sizes
      --sort choice      Sort output by: command, created, id, image, names, runningfor, size, status
      --sync             Sync container state with OCI runtime
  -w, --watch uint       Watch the ps output on an interval in seconds

$ podman pod ps --help

List pods

Description:
  List all pods on system including their names, ids and current state.

Usage:
  podman pod ps  [options]

Aliases:
  ps, ls, list

Options:
      --ctr-ids          Display the container UUIDs. If no-trunc is not set they will be truncated
      --ctr-names        Display the container names
      --ctr-status       Display the container status
  -f, --filter strings   Filter output based on conditions given
      --format string    Pretty-print pods to JSON or using a Go template
  -l, --latest           Act on the latest container podman is aware of
                         Not supported with the "--remote" flag
      --no-trunc         Do not truncate pod and container IDs
      --ns               Display namespace information of the pod
  -q, --quiet            Print the numeric IDs of the pods only
      --sort string      Sort output by created, id, name, or number (default "created")

Because I'm running both a standalone container and a pod with two containers in it, I'll use both commands to show some slight differences between them. I'll start exploring by running podman ps and podman pod ps:

$ podman ps

CONTAINER ID  IMAGE                        COMMAND               CREATED        STATUS             PORTS                 NAMES
055fc7959f58  docker.io/library/wordpress  apache2-foregroun...  3 minutes ago  Up 3 minutes ago   0.0.0.0:8080->80/tcp  wordpress
5bd37169ce0d  docker.io/library/mysql      mysqld                3 minutes ago  Up 3 minutes ago   0.0.0.0:8080->80/tcp  mysql
f8750c81cdb8  k8s.gcr.io/pause:3.2                               3 minutes ago  Up 3 minutes ago   0.0.0.0:8080->80/tcp  a061ffe41575-infra
7c4c01d99ccc  docker.io/library/httpd      httpd-foreground      2 hours ago    Up 36 minutes ago  0.0.0.0:8081->80/tcp  httpd

$ podman pod ps

POD ID        NAME    STATUS   CREATED        INFRA ID      # OF CONTAINERS
a061ffe41575  blog    Running  3 minutes ago  f8750c81cdb8  3

For more detail on the commands' output, check their official documentation (podman ps and podman pod ps). To get more detailed information about your running containers, you can change the output format to use JSON or Go:

$ podman ps --format json

[
  {
    "Command": [
      "apache2-foreground"
    ],
    "Created": 1638753466,
    "CreatedAt": "7 minutes ago",
    "Exited": false,
    "ExitedAt": -62135596800,
    "ExitCode": 0,
    "Id": "055fc7959f58921ef11119b44b1d250558272b523765e639a5e5c3aa2ad3d2a0",
    "Image": "docker.io/library/wordpress",
    "ImageID": "054741915cf1ee661d897b168fe70ce3c35bcf49234d21035654a1f03c143412",
    "IsInfra": false,
    "Labels": null,
    "Mounts": [
      "/var/www/html"
    ],
    "Names": [
      "wordpress"
[...]

To get information about the namespaces your containers are using, try the --namespace option (-ns for short):

$ podman ps --namespace

CONTAINER ID  NAMES               PID     CGROUPNS    IPC         MNT         NET         PIDNS       USERNS      UTS
055fc7959f58  wordpress           11246   4026531835  4026532957  4026532961  4026532842  4026532962  4026531837  4026532956
5bd37169ce0d  mysql               11145   4026531835  4026532957  4026532959  4026532842  4026532960  4026531837  4026532956
f8750c81cdb8  a061ffe41575-infra  11123   4026531835  4026532957  4026532955  4026532842  4026532958  4026531837  4026532956
7c4c01d99ccc  httpd               6016    4026531835  4026532839  4026532837  4026532893  4026532840  4026531837  4026532838

$ podman pod ps --ns

POD ID        NAME    STATUS   CREATED        INFRA ID      <no value>     <no value>  # OF CONTAINERS
a061ffe41575  blog    Running  9 minutes ago  f8750c81cdb8  machine.slice 

To find which pods your containers are running in, use the --pod option (or -p for short)

$ podman ps --pod

CONTAINER ID  IMAGE                        COMMAND               CREATED         STATUS             PORTS                 NAMES               POD ID        PODNAME
055fc7959f58  docker.io/library/wordpress  apache2-foregroun...  11 minutes ago  Up 11 minutes ago  0.0.0.0:8080->80/tcp  wordpress           a061ffe41575  blog
5bd37169ce0d  docker.io/library/mysql      mysqld                11 minutes ago  Up 11 minutes ago  0.0.0.0:8080->80/tcp  mysql               a061ffe41575  blog
f8750c81cdb8  k8s.gcr.io/pause:3.2                               11 minutes ago  Up 11 minutes ago  0.0.0.0:8080->80/tcp  a061ffe41575-infra  a061ffe41575  blog
7c4c01d99ccc  docker.io/library/httpd      httpd-foreground      2 hours ago     Up 43 minutes ago  0.0.0.0:8081->80/tcp  httpd

The output shows that two of my three running containers are within a pod called "blog."

Get container size

You can also sort your running containers' output by different values, like size or creation time. To get the size of a container, use the --size option (-s for short), and you can sort with the --sort option, along with the value you want to sort by:

$ podman ps --size --sort size

CONTAINER ID  IMAGE                        COMMAND               CREATED         STATUS             PORTS                 NAMES               SIZE
f8750c81cdb8  k8s.gcr.io/pause:3.2                               15 minutes ago  Up 15 minutes ago  0.0.0.0:8080->80/tcp  a061ffe41575-infra  0B (virtual 683kB)
7c4c01d99ccc  docker.io/library/httpd      httpd-foreground      2 hours ago     Up 47 minutes ago  0.0.0.0:8081->80/tcp  httpd               2B (virtual 143MB)
5bd37169ce0d  docker.io/library/mysql      mysqld                15 minutes ago  Up 15 minutes ago  0.0.0.0:8080->80/tcp  mysql               7B (virtual 515MB)
055fc7959f58  docker.io/library/wordpress  apache2-foregroun...  15 minutes ago  Up 15 minutes ago  

You can sort by any heading. For instance, this sorts by creation time:

$ podman ps --sort created

CONTAINER ID  IMAGE                        COMMAND               CREATED         STATUS             PORTS                 NAMES
7c4c01d99ccc  docker.io/library/httpd      httpd-foreground      2 hours ago     Up 46 minutes ago  0.0.0.0:8081->80/tcp  httpd
055fc7959f58  docker.io/library/wordpress  apache2-foregroun...  14 minutes ago  Up 14 minutes ago  0.0.0.0:8080->80/tcp  wordpress
5bd37169ce0d  docker.io/library/mysql      mysqld                14 minutes ago  Up 14 minutes ago  0.0.0.0:8080->80/tcp  mysql
f8750c81cdb8  k8s.gcr.io/pause:3.2                               14 minutes ago  Up 14 minutes ago  

Another option is to specify only the columns that you want to see in the output:

$ podman ps --all --format "{{.Names}} {{.Ports}} {{.Mounts}} {{.Status}}"

wordpress 0.0.0.0:8080->80/tcp [/var/www/html] Up 18 minutes ago
mysql 0.0.0.0:8080->80/tcp [/var/lib/mysql] Up 18 minutes ago
a061ffe41575-infra 0.0.0.0:8080->80/tcp [] Up 18 minutes ago
httpd 0.0.0.0:8081->80/tcp [/usr/local/apache2/htdocs] Up 51 minutes ago

You can tailor the output from pod containers by selecting only container IDs, names, or status:

$ podman pod ps --ctr-ids

POD ID        NAME    STATUS   CREATED         INFRA ID      <no value>
a061ffe41575  blog    Running  20 minutes ago  f8750c81cdb8  055fc7959f58,5bd37169ce0d,f8750c81cdb8

$ podman pod ps --ctr-names

POD ID        NAME    STATUS   CREATED         INFRA ID      <no value>
a061ffe41575  blog    Running  20 minutes ago  f8750c81cdb8  wordpress,mysql,a061ffe41575-infra

$ podman pod ps --ctr-status

POD ID        NAME    STATUS   CREATED         INFRA ID      <no value>
a061ffe41575  blog    Running  20 minutes ago  f8750c81cdb8  running,running,running

Get resources being used by containers

To get resource-consumption information about your running containers, retrieve their stats:

$ podman stats

ID            NAME                CPU %   MEM USAGE / LIMIT  MEM %   NET IO             BLOCK IO           PIDS
055fc7959f58  wordpress           0.01%   135.7MB / 2.047GB  6.63%   1.065MB / 671.2kB  2.212MB / 16.38kB  11
5bd37169ce0d  mysql               0.38%   546.1MB / 2.047GB  26.69%  1.065MB / 671.2kB  229.4kB / 626MB    40
7c4c01d99ccc  httpd               0.02%   12.57MB / 2.047GB  0.61%   4.914kB / 12.67kB  -- / --            82
f8750c81cdb8  a061ffe41575-infra  --      204.8kB / 2.047GB  0.01%   1.065MB / 671.2kB  -- / --     

$ podman pod stats

POD           CID           NAME                CPU %  MEM USAGE/ LIMIT   MEM %   NET IO             BLOCK IO           PIDS
a061ffe41575  055fc7959f58  wordpress           2.10%  135.7MB / 2.047GB  6.63%   1.065MB / 671.2kB  2.212MB / 16.38kB  11
a061ffe41575  5bd37169ce0d  mysql               9.67%  546.1MB / 2.047GB  26.69%  1.065MB / 671.2kB  229.4kB / 626MB    40
a061ffe41575  f8750c81cdb8  a061ffe41575-infra  1.80%  204.8kB / 2.047GB  0.01%   1.065MB / 671.2kB  -- / --            1

Show all containers

The podman ps and podman pod ps commands show only the running containers. To list all containers, regardless of their status, use the --all, or -a for short, parameter. In this example, I pause my httpd container before monitoring and then unpause it to demonstrate the different output:

$ podman pause httpd

7c4c01d99cccf70a0c42ebdba458afb8be6d1563de3a91c99519213a4d8654af

$ podman ps

CONTAINER ID  IMAGE                        COMMAND               CREATED         STATUS             PORTS                 NAMES
055fc7959f58  docker.io/library/wordpress  apache2-foregroun...  30 minutes ago  Up 30 minutes ago  0.0.0.0:8080->80/tcp  wordpress
5bd37169ce0d  docker.io/library/mysql      mysqld                30 minutes ago  Up 30 minutes ago  0.0.0.0:8080->80/tcp  mysql
f8750c81cdb8  k8s.gcr.io/pause:3.2                               30 minutes ago  Up 30 minutes ago  0.0.0.0:8080->80/tcp  a061ffe41575-infra

$ podman ps --all

CONTAINER ID  IMAGE                        COMMAND               CREATED         STATUS             PORTS                 NAMES
055fc7959f58  docker.io/library/wordpress  apache2-foregroun...  30 minutes ago  Up 30 minutes ago  0.0.0.0:8080->80/tcp  wordpress
5bd37169ce0d  docker.io/library/mysql      mysqld                30 minutes ago  Up 30 minutes ago  0.0.0.0:8080->80/tcp  mysql
f8750c81cdb8  k8s.gcr.io/pause:3.2                               30 minutes ago  Up 30 minutes ago  0.0.0.0:8080->80/tcp  a061ffe41575-infra
7c4c01d99ccc  docker.io/library/httpd      httpd-foreground      2 hours ago     paused             0.0.0.0:8081->80/tcp  httpd

$ podman unpause httpd

7c4c01d99cccf70a0c42ebdba458afb8be6d1563de3a91c99519213a4d8654af

$ podman ps

CONTAINER ID  IMAGE                        COMMAND               CREATED         STATUS                PORTS                 NAMES
055fc7959f58  docker.io/library/wordpress  apache2-foregroun...  31 minutes ago  Up 31 minutes ago     0.0.0.0:8080->80/tcp  wordpress
5bd37169ce0d  docker.io/library/mysql      mysqld                31 minutes ago  Up 31 minutes ago     0.0.0.0:8080->80/tcp  mysql
f8750c81cdb8  k8s.gcr.io/pause:3.2                               31 minutes ago  Up 31 minutes ago     0.0.0.0:8080->80/tcp  a061ffe41575-infra
7c4c01d99ccc  docker.io/library/httpd      httpd-foreground      2 hours ago     Up About an hour ago  0.0.0.0:8081->80/tcp  httpd

Podman for maximum flexibility

There are more options to explore in the podman ps and podman stats toolset. Try them out to familiarize yourself with the outputs. As you do, you'll become comfortable with the commands, and you'll be able to decide what suits your ongoing needs best.

Podman is gaining more and more followers as a convenient and flexible tool for managing containers and images. Understanding how to use it for things such as listing running containers gives you an advantage in managing containers.

In my next article, I'll explore how to get your container's external internet protocol (IP) address. Until then, you can learn more about Podman from 10 Podman guides to do more with containers in 2022Top 10 container guides for sysadmins, and of course, Podman.io.

Check out these related articles on Enable Sysadmin

Topics:   Podman   Containers  
Author’s photo

Alexon Oliveira

Alexon has been working as a Senior Technical Account Manager in the CEE GCS LATAM team since 2018, focusing on Infrastructure and Management, Integration and Automation, Cloud Computing, and Storage solutions. More about me

On Demand: Red Hat Summit 2021 Virtual Experience

Relive our April event with demos, keynotes, and technical sessions from
experts, all available on demand.

Related Content

OUR BEST CONTENT, DELIVERED TO YOUR INBOX