Your local docker repository can quickly be filled with images that are unnecessary and not associated with any running containers. This could happen if you have an intermediary image that is used in the building of a final image or if you pull down specific versions of an image and leave the old ones which over time will simply build up and steal GBs of hard disk space.

For the first case, ensure that when you are running your docker build command, that you include –force-rm to remove those intermediary images.

docker build --force-rm .

For the second case, simply run a docker image prune -a to prune any images that are not currently associated to a container. Pro tip, schedule this to run on a recurring basis by throwing it into a scheduled task.

In terminal on Mac,

docker image prune -a
# Open the system cron scheduling tool with
crontab -e
# Within the open file, paste the following command which will run docker prune every night at midnight 
0 0 */1 * * docker image prune -a

For more information on the scheduling * * * /1 magic, check out my post on linux scheduling.

Changing crontab -e editor from VIM to Nano.

export EDITOR=/usr/bin/nano
crontab -e

Photo by chuttersnap on Unsplash