The problem
Error response from daemon: conflict: unable to delete 6ab53ec1a8c9 (cannot be forced) - image is being used by running container d65f1c6b798
As the message says you have a container running that uses the image your are trying to delete, thus the error.
You can stop the container and afterwards run the command again, but a better way exists...
A Better Way
docker image rm -f $(docker image ls -aq)
Instead of using the above hack from old days you can use now:
docker image prune -a
The flag -a
will remove all unused docker images, meaning that the ones being used by running containers will not be touched, thus this may be what you want to use in order to achieve what your are trying to do.
If you want to only remove dangling images without removing the ones you already have built then run the same command without the -a
flag:
docker image prune
The help for it:
docker image prune --help
Usage: docker image prune [OPTIONS]
Remove unused images
Options:
-a, --all Remove all unused images, not just dangling ones
--filter filter Provide filter values (e.g. 'until=<timestamp>')
-f, --force Do not prompt for confirmation