Skip to content

Instantly share code, notes, and snippets.

@jcfr
Last active April 2, 2018 13:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcfr/0bb9b695a5f1511a4b66f9e872d44743 to your computer and use it in GitHub Desktop.
Save jcfr/0bb9b695a5f1511a4b66f9e872d44743 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# This script maintained at https://gist.github.com/jcfr/0bb9b695a5f1511a4b66f9e872d44743
#
#
# Source: https://lebkowski.name/docker-volumes/#recap
#
echo "Job started at: $(date +'%T %D %Z')"
# remove exited containers:
docker ps --filter status=dead --filter status=exited -aq | xargs -r docker rm -v
# remove unused images:
docker images --no-trunc | grep '<none>' | awk '{ print $3 }' | xargs -r docker rmi
# remove unused volumes:
docker volume ls -qf dangling=true | xargs -r docker volume rm
echo "Job completed at: $(date +'%T %D %Z')"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment