Docker preserve images policy
I do not believe that there is a way to set this as a global policy.  However, there is a simple command you can run that will "prune" or remove your unused images.

You will want to use docker image prune --filter [options] to achieve this.  Check out the official documentation for information on how to best filter.  As a best practice you should be tagging your images which will make managing of them easier using tools like this.