To remove all images which aren’t associated with a running container:
docker image prune -a
The -a parameter is the crucial bit here.
If you want to force the action to occur without a confirmation prompt, you may add the -f parameter, like so:
docker image prune -af
Note: -af is the same as specifying -a and -f separately