Describes the command to delete all images in Docker with explanation.
command
# warning: use with caution
docker rmi $(docker images -aq)
Use case
When playing around with Docker, it seems images are saved by default in the default machine, and if it gets full, it can cause unnecessary errors.
It’s also troublesome to switch machines by running eval each time, so basically, it’s good to keep plenty of free space on the default machine.
Images that shouldn’t be deleted or frequently used images can be kept on docker hub or on other docker-machines.
# before
$ docker system df
TYPE TOTAL ACTIVE SIZE RECLAIMABLE
Images 40 3 16.43GB 15.79GB (96%)
$ docker-machine ls
NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS
default * virtualbox Running tcp://192.168.99.100: v17.04.0-ce
docker-2 - virtualbox Stopped Unknown
# after
$ docker system df
TYPE TOTAL ACTIVE SIZE RECLAIMABLE
Images 8 3 2.401GB 1.566GB (65%)
Containers 5 0 63B 63B (100%)
Local Volumes 17 5 754.7MB 437.5MB (57%)
Summary
Described the command to delete all images in Docker with explanation.
Please use caution when deleting images.