Skip to content

Instantly share code, notes, and snippets.

@barbazul
Created May 12, 2021 17:50
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save barbazul/396f5f5d22776b5ffaea204571bd81b6 to your computer and use it in GitHub Desktop.
Save barbazul/396f5f5d22776b5ffaea204571bd81b6 to your computer and use it in GitHub Desktop.
Hacky docker clean up solution for my dev environment
# Cleanup Docker weekly
###
# First clear all volumes that are not associated with containers
# This way volumes can live up to 2 weeks without use.
#
15 8 * * 1 docker volume prune
###
# Then clear all images that have not been used in last week.
# These can easily be recovered from Docker Hub when needed.
#
20 8 * * 1 docker image prune --force --all --filter="until=168h"
###
# Finally, clear containers not started in last week
# Note that volumes will not be deleted until next week cron, so if the
# container is recreated within the week, the data will still be available.
#
25 8 * * 1 docker container prune --force --filter="until=168h"
@federflug
Copy link

I suggest adding --force to not ask questions during the cron run:
15 8 * * 1 docker volume prune --force
Thanks for this script :)

@barbazul
Copy link
Author

I suggest adding --force to not ask questions during the cron run: 15 8 * * 1 docker volume prune --force Thanks for this script :)

Never happened to me, but I guess it can't hurt

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