How to Remove a Docker Image
TLDR
Use docker rmi <image> to remove a Docker image. If the image is in use by a container, stop and remove the container first. Use docker image prune to clean up dangling images.
Docker images can pile up quickly, especially during development or CI/CD runs. Removing unused images helps free up disk space and keeps your environment tidy.
Why Remove Docker Images?
- Save Disk Space: Old images can consume gigabytes of storage.
- Reduce Clutter: Fewer images make it easier to manage and find what you need.
- Avoid Conflicts: Outdated images can cause version mismatches.
Listing Images
Before removing, list your images to see what's available:
docker images
This shows all images, their tags, and IDs.
Removing a Specific Image
To remove an image by name or ID:
# Remove by name
docker rmi nginx:alpine
# Remove by image ID
docker rmi 1a2b3c4d5e6f
If the image is used by a container, you'll see an error. Stop and remove the container first:
docker ps -a # Find the container using the image
docker stop <container_id>
docker rm <container_id>
docker rmi <image>
Removing Dangling and Unused Images
Dangling images are layers not tagged or referenced by any container. Clean them up with:
docker image prune
To remove all unused images (not just dangling):
docker image prune -a
Note: This command will remove all images not currently used by any container, so use it with caution.
Best Practices
- Regularly clean up unused images, especially on CI/CD runners.
- Use tags to keep track of image versions.
- Automate cleanup with scheduled jobs if needed.
By managing your Docker images proactively, you keep your development environment fast and reliable.
Good luck with your project!
Related Resources
- Delete All Local Docker Images — bulk cleanup
- Docker No Space Left: How to Clean Up — reclaim disk space
- Remove Old Docker Containers — container cleanup
- Docker Image vs Container — understand the difference
We earn commissions when you shop through the links below.
DigitalOcean
Cloud infrastructure for developers
Simple, reliable cloud computing designed for developers
DevDojo
Developer community & tools
Join a community of developers sharing knowledge and tools
SMTPfast
Developer-first email API
Send transactional and marketing email through a clean REST API. Detailed logs, webhooks, and embeddable signup forms in one dashboard.
QuizAPI
Developer-first quiz platform
Build, generate, and embed quizzes with a powerful REST API. AI-powered question generation and live multiplayer.
Want to support DevOps Daily and reach thousands of developers?
Become a SponsorFound an issue?
Related Posts
Also worth your time on this topic
Delete All Local Docker Images Safely
Learn how to reclaim disk space by removing Docker images, containers, and volumes without breaking your development workflow.
Docker Container Basics
What is the difference between a Docker image and a container? How do they relate to each other?
junior
Docker Multi-Stage Build Optimization
Learn to create efficient Docker images using multi-stage builds to reduce image size and improve security.
60 minutes