Last active
February 21, 2018 21:07
-
-
Save nicosingh/c56c168dfd52fd195054a4f238c09ca9 to your computer and use it in GitHub Desktop.
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 | |
# clean not running containers | |
LIST_STATUS="created restarting removing paused exited dead" | |
for status_element in $LIST_STATUS | |
do | |
for container in $(/usr/bin/docker ps -aq -f status=$status_element) | |
do | |
echo "`date '+[%Y-%m-%d %H:%M:%S]'` gracefully eliminating container ${container}" | |
/usr/bin/docker rm $container | |
done | |
done | |
# clean unused volumes | |
for volume in $(/usr/bin/docker volume ls -q) | |
do | |
echo "`date '+[%Y-%m-%d %H:%M:%S]'` gracefully eliminating volume ${volume}" | |
/usr/bin/docker volume rm $volume | |
done | |
# clean unused images | |
for image in $(/usr/bin/docker images -q) | |
do | |
echo "`date '+[%Y-%m-%d %H:%M:%S]'` gracefully eliminating image ${image}" | |
/usr/bin/docker rmi $image | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment