Skip to content

Instantly share code, notes, and snippets.

@pohmelie
Created September 21, 2020 15:10
Show Gist options
  • Save pohmelie/272b5c2487df60eb7ef1c9db4936b331 to your computer and use it in GitHub Desktop.
Save pohmelie/272b5c2487df60eb7ef1c9db4936b331 to your computer and use it in GitHub Desktop.
Trim docker images for 1 week every sunday 00:00
[Unit]
Description=Prune containers and "old" images (older, than week)
[Service]
ExecStart=/bin/bash -c "docker container prune -f && docker image prune -a -f --filter until=168h"
[Unit]
Description=Run docker-trimmer every weekend
[Timer]
OnCalendar=Sun
Unit=docker-trimmer.service
[Install]
WantedBy=multi-user.target
  1. Copy service and timer to /etc/systemd/system/
  2. sudo systemctl daemon-reload
  3. sudo start docker-trimmer.timer
  4. sudo enable docker-trimmer.timer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment