The steps below will work with or without 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 it

Click “System Tools -> Task Scheduler” in the sidebar

Click “Create Task” in the action bar on the right

Name 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/script

Add the arguments system prune -f and hit OK to anything it says

Goto the “Triggers” tab and click “New”

Change the settings to “Daily” and set the “Start” time to 3AM and recur every 1 day

Click OK and then click OK again for Create Task

Enter in your admin password

MacOS

I 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).