How to Remove All Docker Images Locally

I recently needed to delete all Docker images on my machine.

I knew I could remove individual images.

docker image rm IMAGE_ID

But I didn’t want to do this manually for each image.

1. Remove All Containers

First, we’ll want to remove all containers prior to removing the images.

We can first view all of our containers.

docker container ls

Then delete all containers as well as any associated volumes.

docker rm -vf $(docker ps -a -q)

2. Remove All Images

Next, we can view all of our images.

docker image ls

And finally, we can delete all of our images.

docker rmi -f $(docker images -a -q)

Alternative Option

If we don’t mind deleting everything, we can ignore everything before this section, and use prune.

docker system prune -a --volumes

WARNING! This will remove: 1) all stopped containers, 2) all networks not used by at least one container, 3) all volumes not used by at least one container, 4) all images without at least one container associated to them, and 5) all build cache