From 52febd39d60247059d8321449e4193a2c9e7482f Mon Sep 17 00:00:00 2001 From: Grant Slater Date: Fri, 2 Dec 2022 12:59:05 +0000 Subject: [PATCH 1/1] docker: Add old image/container cleanup service --- cookbooks/docker/recipes/default.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/cookbooks/docker/recipes/default.rb b/cookbooks/docker/recipes/default.rb index 890c1c21f..3d7fd2104 100644 --- a/cookbooks/docker/recipes/default.rb +++ b/cookbooks/docker/recipes/default.rb @@ -42,3 +42,21 @@ service "docker" do action [:enable, :start] subscribes :restart, "template[/etc/docker/daemon.json]" end + +systemd_service "docker-system-prune" do + description "Cleanup up unused docker images and containers" + after ["docker.service"] + wants ["docker.service"] + user "root" + exec_start "/usr/bin/docker system prune --all --force" + sandbox :enable_network => true + memory_deny_write_execute false + restrict_address_families "AF_UNIX" +end + +systemd_timer "docker-system-prune" do + description "Cleanup up unused docker images and containers" + on_boot_sec "2h" + on_unit_active_sec "7d" + randomized_delay_sec "4h" +end -- 2.39.5