Skip to content

Instantly share code, notes, and snippets.

@jeonguk
Created January 19, 2018 00:55
Show Gist options
  • Save jeonguk/08d6b30c01eba1fafc47a6e08a6a6a3a to your computer and use it in GitHub Desktop.
Save jeonguk/08d6b30c01eba1fafc47a6e08a6a6a3a to your computer and use it in GitHub Desktop.
clean docker all images container volume
#!/bin/bash
###################################################
#
# Simple Shell script to clean/remove all container/images
#
# The script will
# - first stop all running containers (if any),
# - remove containers
# - remove images
# - remove volumes
###################################################
# stop all running containers
echo '#############################################'
echo 'Stopping running containers (if available)...'
echo '#############################################'
docker stop $(docker ps -aq)
# remove all stopped containers
echo '##############################################'
echo 'Removing containers ..'
echo '##############################################'
docker rm $(docker ps -aq)
# remove all images
echo '##############################################'
echo 'Removing images ...'
echo '##############################################'
docker rmi $(docker images -q)
# remove all stray volumes if any
echo '##############################################'
echo 'Revoming docker container volumes (if any)'
echo '##############################################'
docker volume rm $(docker volume ls -q)
@jeonguk
Copy link
Author

jeonguk commented Jan 19, 2018

Allowing everyone to execute the script, enter:

chmod +x script.sh
or
chmod 0755 script.sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment