docker/rmi

Remove Image

Remove one or more images from the local system.

images
cleanup

Command

docker rmi

Explanation

docker rmi removes one or more image layers by reference. If containers depend on the image, removal will fail unless forced with -f. It’s essential for managing storage and maintaining a clean environment.

Common Use Cases

  • Reclaim disk space
  • Remove outdated or unused images
  • Clean up build artifacts

Best Practices

  • Run docker ps -a first to ensure image isn’t in use
  • Combine with docker image prune for cleanup automation

Common Mistakes to Avoid

  • Attempting to remove images used by running containers
  • Using -f carelessly and deleting critical images

Troubleshooting

Problem: Error: image is being used by stopped container

Solution: Remove dependent container first or use docker rm <container>.

Examples

Remove single image

docker rmi myimage

Remove all images

docker rmi $(docker images -q)