To delete Docker images, you can use the docker rmi command followed by the image ID or image name. Here are the steps and options you can use to delete Docker images:
1. List Docker Images
Before deleting images, you might want to list your current images:
bash
docker images
2. Delete a Docker Image
To delete a specific image, use:
bash
docker rmi <image_id>
or
bash
docker rmi <image_name>:<tag>
For example:
bash
docker rmi my_image:latest
3. Force Deletion
If the image is being used by a stopped container, you will need to force the deletion using:
bash
docker rmi -f <image_id>
or
bash
docker rmi -f <image_name>:<tag>
4. Remove Unused Images
To clean up all unused images, you can use:
bash
docker image prune
This will remove dangling images (those not tagged and not referenced by any container).
5. Remove All Images
If you want to remove all images from your system, you can use:
bash
docker rmi $(docker images -q)
Note: This command will fail if any images are currently in use by running containers.
6. Remove All Unused Images, Containers, Networks
To remove all unused objects (not just images, but also containers and networks), you can use:
bash
docker system prune
If you want to remove everything including unused images, containers, and networks, use:
bash
docker system prune -a
Be cautious with this command as it will delete a lot of data.
Summary
Use docker rmi to remove specific images.
Use -f flag to force delete.
Use docker image prune and docker system prune for cleaning up unused images and other resources.
Always ensure that you are deleting the right images, especially when using commands that force deletion or remove multiple resources at once.