Home > Software design >  How to display total number of running containers in docker?
How to display total number of running containers in docker?

Time:11-07

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?

CodePudding user response:

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

CodePudding user response:

Have a look here https://docs.docker.com/engine/reference/commandline/ps/#formatting

If you dont use the table directive it wont show the headers

You should be able to pipe that in to wc -l

  • Related