Skip to content

Instantly share code, notes, and snippets.

@mrgarymartin
Last active December 9, 2020 17:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrgarymartin/43f036440155e0c63a302cc608c094e5 to your computer and use it in GitHub Desktop.
Save mrgarymartin/43f036440155e0c63a302cc608c094e5 to your computer and use it in GitHub Desktop.
This script installs automated docker cleanup via "docker image prune"
#!/bin/sh
# This script installs automated docker cleanup via "docker image prune"
# onto systemd-based systems.
# It requires that docker is installed properly
# source: https://techoverflow.net/2019/10/03/how-to-automatically-cleanup-prune-docker-images-daily/
cat >/etc/systemd/system/PruneDocker.service <<EOF
[Unit]
Description=PruneDocker
[Service]
Type=oneshot
ExecStart=/usr/bin/docker system prune -a -f
WorkingDirectory=/tmp
EOF
cat >/etc/systemd/system/PruneDocker.timer <<EOF
[Unit]
Description=PruneDocker
[Timer]
OnBootSec=15min
OnCalendar=daily
Persistent=true
[Install]
WantedBy=timers.target
EOF
# Enable and start service
systemctl enable PruneDocker.timer && sudo systemctl start PruneDocker.timer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment