Today I Learned: collection of notes, tips and tricks and stuff I learn from day to day working with computers and technology as a developer

View project on GitHub

Automatically Clean up after Docker Daily

The command we are going to be executing is docker system prune -f it removes all stopped containers, all unused networks, dangling images and empties build caches.

On MacOS create a file in: ~/Library/LaunchAgents named com.jonasbn.dockersystemprune.plist exchange the jonasbn for your own username.

Insert the following contents:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
<plist version="1.0">
    <string>/usr/local/bin/docker system prune -f</string>

Now install the timed job:

$ launchctl load -w ~/Library/LaunchAgents/com.jonasbn.dockersystemprune.plist

You can always uninstall it again using:

$ launchctl unload ~/Library/LaunchAgents/com.jonasbn.dockersystemprune.plist