We use the docker system prune command to remove all stopped containers, all unused networks, all dangling images, and build caches. We gonna execute the same command from the windows scheduled task to automatically clean up docker resources.
We are going to create a Windows Scheduled task with a PowerShell script to automatically delete all stopped containers, all dangling images, all unused networks, and build caches.
The following script will setup Scheduled tasks to be run at 3 am UTC which will prune docker.
Create a .ps1 file (ex: CreateDockerPruneWtask.ps1) with the below PowerShell script
Run the PowerShell script to create a Windows scheduled task, before running the script, please check the
docker.exe file path, if needed change the path according to the docker installation.
You can verify the task in Task Scheduler. to launch Task Scheduler from PowerShell use
I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.
I am Arjun from Hyderabad (India). I have been working as a software engineer from the last 7+ years, and it is my passion to learn new things and implement them as a practice. Aside from work, I like gardening and spending time with pets.