Docker makes it easy to build and run containerized applications—but over time, your system can get cluttered with unused Docker images. Whether you’re cleaning up space, removing an old version, or just staying organized, it’s helpful to know how to remove Docker images properly and safely.
In this post, we’ll cover different ways to delete Docker images using the CLI, when you can (and can’t) remove them, and how to clean up your system efficiently.
🔍 What Is a Docker Image?
A Docker image is a read-only template used to create containers. Images can be:
- Pulled from Docker Hub (e.g.
nginx
,ubuntu
) - Built locally via a
Dockerfile
- Tagged for different versions (e.g.
my-app:v1
,my-app:latest
)
Removing unused images helps save disk space and reduce clutter in development environments.
✅ How to List Docker Images
Before removing anything, list the images on your system:
docker images
Output:
REPOSITORY TAG IMAGE ID CREATED SIZE
my-app latest a1b2c3d4e5f6 2 hours ago 150MB
nginx stable f2g3h4i5j6k7 3 days ago 133MB
Use the IMAGE ID, repository:tag, or both to remove a specific image.
🗑️ Method 1: Remove a Specific Docker Image
A. By Image Name and Tag
docker rmi my-app:latest
B. By Image ID
docker rmi a1b2c3d4e5f6
✅ Docker will remove the image only if no containers are using it. Otherwise, it will show an error.
🛠️ Method 2: Force Remove an Image
To forcefully delete an image (even if it’s being used by stopped containers):
docker rmi -f my-app:latest
⚠️ Use with caution. Make sure you’re not removing an image used by critical services.
🧹 Method 3: Remove All Unused (Dangling) Images
“Dangling” images are layers not tagged or associated with any container:
docker image prune
Add -a
to remove all unused images, not just dangling ones:
docker image prune -a
🔐 Only use
-a
if you’re sure none of those images are needed anymore.
🧼 Method 4: Clean Everything (System Prune)
To clean up images, containers, networks, and build cache in one go:
docker system prune
Add -a
to also remove unused images:
docker system prune -a
🧠 This is the most aggressive cleanup option. Use with care in production environments.
📝 Conclusion
Cleaning up Docker images is an essential part of managing your local Docker environment. Whether you’re removing one specific image or performing a full system prune, Docker provides flexible options to keep your system lean and efficient.
🔑 Summary
Task | Command |
---|---|
Remove image by name | docker rmi my-image:tag |
Remove image by ID | docker rmi <image-id> |
Force remove image | docker rmi -f <image> |
Remove dangling images | docker image prune |
Remove all unused images | docker image prune -a |
Remove all unused resources | docker system prune -a |