Created
January 19, 2018 00:55
-
-
Save jeonguk/08d6b30c01eba1fafc47a6e08a6a6a3a to your computer and use it in GitHub Desktop.
clean docker all images container volume
This file contains 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 | |
################################################### | |
# | |
# 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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Allowing everyone to execute the script, enter: