crontool
Paste a schedule, read it in English, see the next runs.

Clean Up Docker with Cron (system prune)

To reclaim disk space, run docker system prune from cron on a schedule. It removes stopped containers, unused networks, and dangling images. Add -f to skip the confirmation prompt so it runs unattended.

The crontab line

Run sudo crontab -e (docker needs root) and add (3 AM every Sunday):

0 3 * * 0 /usr/bin/docker system prune -af >> /var/log/docker-prune.log 2>&1

What the flags mean

-f skips the "Are you sure?" prompt (required for cron). -a also removes unused images not just dangling ones. Add --volumes only if you are certain no needed data lives in anonymous volumes.

Use the absolute path

Find docker with which docker. Cron's PATH won't include it, so use /usr/bin/docker to avoid 'docker: command not found'.

Be careful with -a and --volumes

-a deletes any image without a running container — it will re-pull on next use. --volumes can delete data; omit it unless you know what's stored there.

FAQ

How do I clean up Docker automatically with cron?

0 3 * * 0 /usr/bin/docker system prune -af runs every Sunday at 3 AM. The -f flag skips the confirmation so it runs unattended.

What does docker system prune -af remove?

Stopped containers, unused networks, and all unused images (-a). Add --volumes to also remove anonymous volumes, but only if you're sure no data lives there.

Why does docker fail in my crontab?

Cron's minimal PATH lacks docker and the user may not have permission. Use /usr/bin/docker and run via sudo crontab -e as root.