docker-image-rm
TLDR
Remove one or more images given their names
Force remove an image
Remove an image without deleting untagged parents
Display help
SYNOPSIS
docker image rm [OPTIONS] IMAGE [IMAGE...]
docker rmi [OPTIONS] IMAGE [IMAGE...]
PARAMETERS
-f, --force
Force image removal by stopping/removing dependent containers first
--no-prune
Do not delete untagged parent images after removal
DESCRIPTION
The docker image rm command (alias: docker rmi) deletes one or more specified Docker images from the local Docker storage on the host. Docker images consist of layered filesystems; removing an image deletes its tags but retains shared layers used by other images to avoid data loss. The command fails if the image is referenced by any container (running or stopped) unless forced.
Specify images by repository name, tag (e.g., nginx:latest), digest (e.g., sha256:abc123), or ID. Multiple images can be listed. By default, it prunes unreferenced (dangling) parent images after removal to reclaim space. Use --no-prune to skip this.
Force mode (-f) stops and removes dependent containers first, then deletes the image and unused layers. Ideal for cleanup after builds, tests, or when managing large image collections. Always verify with docker image ls before removal to avoid deleting needed images.
This promotes efficient disk usage in development, CI/CD, and production environments using Docker Engine.
CAVEATS
Fails if image used by containers without -f; multi-tagged images need all tags removed or force; does not affect remote registries.
EXAMPLES
docker image rm nginx:1.21 Remove specific tagged image
docker image rm -f $(docker image ls -q --filter dangling=true) Force-remove dangling images
EXIT STATUS
0 on success
1 on error (e.g., image in use, invalid ID)
HISTORY
Introduced in Docker 1.0 (2014); evolved in Docker Engine with layer optimizations in v17.05+; maintained by Docker Inc./Moby Project.


