Skip to content

Instantly share code, notes, and snippets.

@xtenduke
Created November 10, 2019 18:45
Show Gist options
  • Save xtenduke/36d5f4c9404c39ca7ea4e727651cdb97 to your computer and use it in GitHub Desktop.
Save xtenduke/36d5f4c9404c39ca7ea4e727651cdb97 to your computer and use it in GitHub Desktop.
Stop all docker containers
##BEERWARE LICENSE" (Revision 42):
# github.com/xtenduke wrote this code. As long as you retain this
# notice, you can do whatever you want with this stuff. If we
# meet someday, and you think this stuff is worth it, you can
# buy me a beer in return.
# ------------------------------------------------------------
#!/bin/bash
count='0'
function getRunningCount() {
count=$(docker ps -q | wc -l)
}
echo "Stop all Docker containers..."
getRunningCount
if [ "$count" -eq "0" ]; then
echo "No containers running... exiting";
exit 0;
fi
echo "currently running:" $count
echo 'killing.......'
echo -n $(docker stop $(docker ps -q))
getRunningCount
if [ "$count" -eq "0" ]; then
echo -e "\nSuccess";
exit 0;
else
echo "Failed to kill all containers, running:" $count
exit 1;
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment