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

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

docker image rm [OPTIONS] IMAGE [IMAGE...]

Parameters

ParameterDescription
-f Force removal, e.g. of an image used by a stopped container.

Examples

Untag without deleting the image
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.

Images in use by a container
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.

Was this page helpful?