How do you remove a Docker image?
Removal is done using the docker rmi command.
1. View images
bash
docker images2. Remove a specific image
bash
docker rmi IMAGE_NAMEor by ID:
bash
docker rmi IMAGE_ID3. If the image is used by a container
First remove the container:
bash
docker rm CONTAINER_IDAnd then again:
bash
docker rmi IMAGE_ID4. Remove all unused images
bash
docker image pruneor, radically (everything unused):
bash
docker system prune -aMain rule: as long as a container is created or running from an image, the image cannot be removed.
Short Answer
Interview readyPremium
A concise answer to help you respond confidently on this topic during an interview.