skip to Main Content

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?

2

Answers


  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

    Login or Signup to reply.
  2. 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
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search