Skip to content

Instantly share code, notes, and snippets.

@sridharsam
Forked from blackandred/main.yml
Last active October 27, 2021 14:54
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 sridharsam/57bfaf4916b255eef1ed0160beb51553 to your computer and use it in GitHub Desktop.
Save sridharsam/57bfaf4916b255eef1ed0160beb51553 to your computer and use it in GitHub Desktop.
Ansible + Docker: Clean up unused, old containers and images to free up the disk space
#
# Created for free for the anarchist movement around the world.
# See iwa-ait.org, zsp.net.pl, wolnosciowiec.net
#
- name: Schedule a clean up for Docker images
become: yes
cron:
name: "docker-clean-up-images"
minute: "0"
hour: "22"
job: "docker rmi $(docker images | awk '/^<none>/ { print $3 }') 2> /dev/null"
day: "10"
- name: Schedule a clean up for Docker unused containers
become: yes
cron:
name: "docker-clean-up-containers"
minute: "0"
hour: "22"
job: "docker ps --filter 'status=exited' | grep 'weeks ago' | awk '{print $1}' | xargs --no-run-if-empty docker rm 2> /dev/null"
day: "5"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment