Docker Tip #32: Automatically Clean Up after Docker Daily — Nick Janetakis

Ask questions Research chat →

https://nickjanetakis.com/blog/docker-tip-32-automatically-clean-up-after-docker-daily · scraped

deploy

Attachments

Scraped Content

— 484 words · 2026-02-14 03:18:08 UTC ·

Excerpt

Updated on January 24, 2020 in #dockerDocker Tip #32: Automatically Clean Up after Docker DailyLearn how to automatically remove dangling Docker images and other resources on a daily basis for Linux, Windows and MacOS.The command we’re going to be executing is docker system prune -f which will remove all stopped containers, all unused networks, all dangling images and build caches.We’ll want to automatically execute this command every day at 3AM, but how we do it will depend on what OS you’re using. So here’s how to do it on all major operating systems.# LinuxWe have access to the cron utility, so this will be simple. Run crontab -e, pick an editor (nano) if you haven’t done so already and then add this line to the bottom and save it:0 3 * * * /usr/bin/docker system prune -fDocker is most likely installed at /usr/bin/docker but you can verify that by running which docker. Change the path if you need to. Also make sure the line isn’t commented out with a #.# WindowsThe steps below will
Updated on January 24, 2020 in #dockerDocker Tip #32: Automatically Clean Up after Docker DailyLearn how to automatically remove dangling Docker images and other resources on a daily basis for Linux, Windows and MacOS.The command we’re going to be executing is docker system prune -f which will remove all stopped containers, all unused networks, all dangling images and build caches.We’ll want to automatically execute this command every day at 3AM, but how we do it will depend on what OS you’re using. So here’s how to do it on all major operating systems.# LinuxWe have access to the cron utility, so this will be simple. Run crontab -e, pick an editor (nano) if you haven’t done so already and then add this line to the bottom and save it:0 3 * * * /usr/bin/docker system prune -fDocker is most likely installed at /usr/bin/docker but you can verify that by running which docker. Change the path if you need to. Also make sure the line isn’t commented out with a #.# WindowsThe steps below will work with older versions of Windows or no WSL as long as you’re using Docker for Windows. If you are using Docker Toolbox you will need to change step 8 to launch the Docker Quickstart Terminal and pass in the Docker command to that as an argument.Here’s how to do it using the built in Windows Task Scheduler:Search for “Computer Management” and run itClick “System Tools -> Task Scheduler” in the sidebarClick “Create Task” in the action bar on the rightName it “Docker-System-Prune”Change the security option to “Run whether user is logged on or not”Change “Configure for” (dropdown box) to “Windows 10”Goto the “Actions” tab and click “New”Enter in C:\Program Files\Docker\Docker\Resources\bin\docker.exe as the Program/scriptAdd the arguments system prune -f and hit OK to anything it saysGoto the “Triggers” tab and click “New”Change the settings to “Daily” and set the “Start” time to 3AM and recur every 1 dayClick OK and then click OK again for Create TaskEnter in your admin password# macOSI don’t use a Mac but my buddy Scott does, so he provided me the steps listed below for LaunchD (a default scheduler on MacOS that is supposed to replace cron).Create the LaunchD based schedule file:sudo touch /Library/LaunchDaemons/DockerSystemPrune.plistAdd this content to the above file and save it:<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Label</key> <string>DockerSystemPrue</string> <key>Program</key> <string>/usr/local/bin/docker system prune -f</string> <key>StartCalendarInterval</key> <dict> <key>Hour</key> <integer>3</integer> <key>Minute</key> <integer>0</integer> </dict> </dict> </plist> Load the task into LaunchD:launchctl load -w /Library/LaunchDaemons/DockerSystemPrune.plistAt this point it’s activated and you’re good to go.Over 5 days you'll get 1 email per day that includes video and text from the premium Dive Into Docker course. By the end of the 5 days you'll have hands on experience using Docker to serve a website. Comments Please enable JavaScript to view the comments powered by Disqus. © 2026 Nick JanetakisFollow @nickjanetakis GitHub | YouTube

Visibility

Visible to everyone

Reading Status

Related Bookmarks

My Note


Saved!

Annotations

Export as Markdown
+ Annotate selection

Add Annotation