Z
As you work with Docker, your system can quickly accumulate a large number of images, containers, volumes, and networks—many of which become unused or outdated. These unused Docker images can consume significant disk space over time.
In this article, we’ll walk you through how to safely remove old and unused Docker images using a variety of commands and best practices.
🔍 What Are Unused Docker Images?
Docker images are considered “unused” when they:
- Are dangling: Images not tagged and not referenced by any container.
- Are untagged or orphaned: Created during a build process but not properly tagged.
- Are not in use: No containers are running or referencing them.
✅ List Docker Images
To begin, list all images on your system:
docker images
You’ll see columns for REPOSITORY, TAG, IMAGE ID, and SIZE.
🧼 1. Remove Dangling Images (Untagged Images)
Dangling images are often leftover from build processes.
🔹 Command:
docker image prune
🔹 What it does:
- Removes images with
<none>
as their name and tag. - Safe to use—it only deletes unreferenced layers.
✅ Add -f
to skip confirmation:
docker image prune -f
🧼 2. Remove All Unused Images
If you want to delete all images not used by a running or stopped container, use:
docker image prune -a
⚠️ Warning:
- This will remove all unused images, not just dangling ones.
- Containers depending on these images will be broken if removed.
✅ Use with force flag:
docker image prune -a -f
🛑 3. Remove Specific Images Manually
You can remove individual images using their image ID or name:
docker rmi IMAGE_ID
Example:
docker rmi ubuntu:18.04
✅ Tip: Use
docker images
to find the correct ID or tag.
🧰 4. Clean Everything (System-Wide Prune)
If you want to clean up everything not in use, including:
- Containers (stopped)
- Images (unused)
- Networks (unused)
- Volumes (optional)
🔹 Command:
docker system prune
Add -a
to include unused images:
docker system prune -a
Add --volumes
to clean volumes too:
docker system prune -a --volumes
⚠️ Caution:
This will remove a lot of data—double-check before running!
🧠 Best Practices for Managing Docker Images
Practice | Benefit |
---|---|
Tag and version images | Avoid dangling images during builds |
Prune regularly | Reclaim disk space |
Use named volumes | Prevent data loss during prune |
Avoid unnecessary docker build runs | Prevent duplicate image layers |
🧪 Quick Recap of Commands
Task | Command |
---|---|
Remove dangling images | docker image prune |
Remove all unused images | docker image prune -a |
Remove specific image | docker rmi IMAGE_ID |
System-wide cleanup | docker system prune -a --volumes |
🚀 Final Thoughts
Cleaning up unused Docker images is essential for saving disk space and maintaining performance. Docker provides powerful tools like prune
and rmi
to help you manage your environment with ease.
💡 Pro tip: Automate cleanup with a cron job or regularly scheduled task to keep your system lean and clean.