Last active
December 9, 2020 17:37
-
-
Save mrgarymartin/43f036440155e0c63a302cc608c094e5 to your computer and use it in GitHub Desktop.
This script installs automated docker cleanup via "docker image prune"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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