-
-
Save ndrean/b2af3c7316ceceec2a4947d54dfdc9ab to your computer and use it in GitHub Desktop.
A simple script to count the containers on a Docker host.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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