How Can I Delete All Local Docker Images?

Docker is a powerful tool for containerization, but over time, your system can become cluttered with unused images. These consume significant disk space and can slow down Docker operations.

In this guide, we’ll show you how to safely delete all local Docker images in just a few commands.


🧾 First, Why Clean Up Docker Images?

Each time you build or pull a Docker image, it stays in your system. Over time, these add up and can:

  • Occupy several gigabytes of disk space
  • Cause confusion when selecting image tags
  • Slow down operations like listing or searching images

🔍 Step 1: List All Docker Images

To see what’s currently stored locally, run:

docker images

or for more detailed output:

docker image ls

🗑️ Step 2: Delete All Docker Images

To remove all local Docker images, use this one-liner:

docker rmi $(docker images -q)

Explanation:

  • docker images -q: lists all image IDs.
  • docker rmi: removes the images by ID.

⚠️ Note: If an image is being used by a container (even stopped), this command might fail. To force deletion, add the -f flag:

docker rmi -f $(docker images -q)

🧼 Optional: Remove Unused Containers, Volumes, and Networks

To clean up everything not actively in use:

docker system prune -a

Add --volumes to also remove unused volumes:

docker system prune -a --volumes

⚠️ This is destructive—double-check that you don’t need any of the images, containers, or volumes.


🧠 Final Tips

  • Use docker image prune to delete unused images only.
  • Regularly run docker system df to monitor disk usage.
  • Consider automating cleanup with cron jobs or scheduled scripts.

✅ Summary

ActionCommand
List all imagesdocker images
Remove all imagesdocker rmi $(docker images -q)
Force remove all imagesdocker rmi -f $(docker images -q)
Full cleanupdocker system prune -a --volumes

By staying on top of unused Docker assets, you’ll keep your system fast and efficient.

Sharing Is Caring:

Leave a Comment