Skip to content

Instantly share code, notes, and snippets.

@nicosingh
Last active February 21, 2018 21:07
Show Gist options
  • Save nicosingh/c56c168dfd52fd195054a4f238c09ca9 to your computer and use it in GitHub Desktop.
Save nicosingh/c56c168dfd52fd195054a4f238c09ca9 to your computer and use it in GitHub Desktop.
#!/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