You cannot remove an image if there are existing containers based on it. Always run
docker container ls -a and docker container rm <container_id> as needed.1. List All Images
To view all images on your host:52862a02e4e9 has two tags: httpd:alpine and httpd:customv1.
2. Remove a Single Tag
When you rundocker image rm <repository>:<tag>, Docker:
- Removes the tag (soft link).
- Deletes the image layers only if no other tags reference them.
customv1 tag:
httpd:alpine still points to the same layers, only the tag is removed.
Verify the remaining images:
3. Prune All Unused Images
If you have many dangling or unreferenced images, use:This command deletes all images not currently used by at least one container. Use with caution in production.
Common Docker Image Removal Commands
| Command | Description |
|---|---|
docker image ls | List all images |
docker image rm <repository>:<tag> | Remove a specific image tag (and layers if orphan) |
docker image prune | Delete dangling images (untagged) |
docker image prune -a | Delete all unused images |
docker container ls -a | List all containers (to identify dependencies) |
docker container rm <container_id> | Remove specified container |