Skip to content

Instantly share code, notes, and snippets.

@pprishchepa
Forked from ggtools/countContainers.sh
Created November 28, 2016 13:54
Show Gist options
  • Save pprishchepa/f8d5a2d921e2c1bf8483dea6072b5adb to your computer and use it in GitHub Desktop.
Save pprishchepa/f8d5a2d921e2c1bf8483dea6072b5adb to your computer and use it in GitHub Desktop.
A simple script to count the containers on a Docker host.
#!/bin/bash
function countContainers() {
docker ps -q $1 | wc -l
}
function countCrashedContainers() {
docker ps -a | grep -v -F 'Exited (0)' | grep -c -F 'Exited ('
}
TYPE=${1-all}
case $TYPE in
running) COUNT_FUNCTION="countContainers"; shift;;
crashed) COUNT_FUNCTION="countCrashedContainers"; shift;;
all) COUNT_FUNCTION="countContainers -a"; shift;;
esac
$COUNT_FUNCTION
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment