Skip to content

Instantly share code, notes, and snippets.

@RogWilco
Created October 10, 2019 23:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RogWilco/a2365271c6ad4594306964f434d6ce44 to your computer and use it in GitHub Desktop.
Save RogWilco/a2365271c6ad4594306964f434d6ce44 to your computer and use it in GitHub Desktop.
Docker Nuke -> it's the only way to be sure!
#!/usr/bin/env bash
docker_nuke() {
local COLOR_RED="\033[0;31m"
local COLOR_GREEN="\033[0;32m"
local COLOR_CYAN="\033[0;36m"
local containers="$(docker ps -aq)"
local images="$(docker images -q)"
local success="$COLOR_GREEN✓"
local failure="$COLOR_RED✘"
local result_skip="$COLOR_CYAN⌀"
# Stop and remove all containers
if [ ! -z "$containers" ]; then
echo "Stopping all runnning containers..."
(docker stop $(docker ps -aq) 2>&1 > /dev/null && echo " $success") || echo " $failure"
echo "Removing all containers..."
(docker rm $(docker ps -aq) && echo " $success") || echo " $failure"
fi
# Remove all images
if [ ! -z "$images" ]; then
echo "Removing all images..."
(docker rmi $(docker images -q) 2>&1 > /dev/null && echo " $success") || echo " $failure"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment