Skip to content

Instantly share code, notes, and snippets.

@ruby232
Forked from ggtools/countContainers.sh
Last active February 15, 2020 01:02
Show Gist options
  • Save ruby232/c3edc6c2737a4994c1011f31d9ed8118 to your computer and use it in GitHub Desktop.
Save ruby232/c3edc6c2737a4994c1011f31d9ed8118 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
# Ordenar container por CPU
#docker stats --no-stream --format "table {{.Name}}\t{{.Container}}\t{{.CPUPerc}}\t{{.MemUsage}}" | sort -k 3 -h
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment