Sunday, November 6, 2022

[FIXED] How to display total number of running containers in docker?

Issue

docker ps

Displays all the running containers

I want to display the total number of running containers

The command,

docker ps | wc -l

displays the line count but also counts headers as lines.

How do I exclude headers? Also, is there another way to print the total number of running containers?


Solution

docker info display the number of running containers like next:

Server:
Containers: 116
 Running: 3
 Paused: 0
 Stopped: 113

You could format the output using next to get the running containers:

$ docker info --format '{{json .ContainersRunning}}'
3


Answered By - atline
Answer Checked By - Timothy Miller (PHPFixing Admin)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.