Subham
Subham

Reputation: 187

How to display total number of running containers in docker?

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?

Upvotes: 0

Views: 1357

Answers (2)

atline
atline

Reputation: 31604

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

Upvotes: 2

Jason Woods
Jason Woods

Reputation: 1

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

Upvotes: 0

Related Questions