Docker Engine 29 reference · Images
docker image rm Command (Docker CLI)
Remove local images or tags; an image used by a container must be forced, and shared layers stay until unused.
Docker Engine 29
Syntax
docker image rm [OPTIONS] IMAGE [IMAGE...]
Parameters
| Parameter | Description |
|---|---|
-f |
Force removal, e.g. of an image used by a stopped container. |
Examples
docker tag alpine:3.24 rc-ref-rmi:old
docker image rm rc-ref-rmi:old
echo "alpine:3.24 still present: $(docker image ls -q alpine:3.24 | wc -l)"
Output
Untagged: rc-ref-rmi:old alpine:3.24 still present: 1
Run this on your computer — see “Get Started” for setup.
printf 'FROM alpine:3.24\nRUN echo v1 > /version\n' > Dockerfile
docker build -q -t rc-ref-rmi:only . > /dev/null
docker run --name rc-ref-rmi-c rc-ref-rmi:only true
id=$(docker image inspect rc-ref-rmi:only --format '{{.Id}}')
docker image rm "$id" > /dev/null 2>&1 || echo 'removing the image by ID is refused: a container still uses it'
docker rm rc-ref-rmi-c > /dev/null; docker image rm rc-ref-rmi:only > /dev/null && echo 'removed after deleting the container'
Output
removing the image by ID is refused: a container still uses it removed after deleting the container
Run this on your computer — see “Get Started” for setup.
Related
docker image ls· List local images with repository, tag, ID and size; filter dangling images and format the output.docker tag· Give an existing image another name, typically a registry path and version before pushing; tags are pointers to the same image.- Disk Usage and Cleanup · tutorial