Skip to content

Instantly share code, notes, and snippets.

@sirkonst
Created November 22, 2018 12:25
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sirkonst/413475ee055a588c58661363c461122e to your computer and use it in GitHub Desktop.
Save sirkonst/413475ee055a588c58661363c461122e to your computer and use it in GitHub Desktop.
Remove unused docker resources with systemd (service and timer)
[Unit]
Description=Remove unused docker resources
Documentation=https://docs.docker.com/v17.09/engine/admin/pruning/
After=docker.service
[Service]
Type=oneshot
ExecStart=/usr/bin/docker system prune -f --filter "until=744h"
ExecStart=/usr/bin/docker volume prune -f
TimeoutSec=10m
[Install]
WantedBy=multi-user.target
[Unit]
Description=Run docker-prune daily
[Timer]
OnCalendar=daily
Persistent=true
[Install]
WantedBy=timers.target
@sirkonst
Copy link
Author

  • Put files into /etc/systemd/system/
  • Run systemctl daemon-reload
  • Run systemctl enable docker-prune.timer
  • Run systemctl start docker-prune.timer

@sirkonst
Copy link
Author

Run manually: systemctl start docker-prune
Check result: systemctl status docker-prune or journalctl -u docker-prune

@stueja
Copy link

stueja commented Oct 15, 2023

Should you not want to start docker-prune.timer right after configuration but rather at the configured time, run systemctl restart timers.target instead. (https://unix.stackexchange.com/questions/563896/systemd-timer-will-not-fire/563897#563897)

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