Skip to content

Instantly share code, notes, and snippets.

@ggtools
Created November 17, 2014 13:27
Show Gist options
  • Save ggtools/af819efc6b8e3287616c to your computer and use it in GitHub Desktop.
Save ggtools/af819efc6b8e3287616c 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