Skip to main content

How do you remove a Docker image?

Removal is done using the docker rmi command.

1. View images

bash
docker images

2. Remove a specific image

bash
docker rmi IMAGE_NAME

or by ID:

bash
docker rmi IMAGE_ID

3. If the image is used by a container

First remove the container:

bash
docker rm CONTAINER_ID

And then again:

bash
docker rmi IMAGE_ID

4. Remove all unused images

bash
docker image prune

or, radically (everything unused):

bash
docker system prune -a

Main rule: as long as a container is created or running from an image, the image cannot be removed.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.