Docker

To delete images in Docker, you can use the docker rmi or docker image rm commands. Here are the steps:
  1. List the Docker images: Before you can delete an image, you need to know its ID or name. You can list all Docker images on your system with the docker images command:
    docker images
    
    This will display a list of all Docker images along with their repository name, tag, image ID, creation date, and size.
  2. Delete a Docker image: Once you have the image ID or name, you can delete the image. Replace <image-id> with the ID of the image you want to delete:
    docker rmi <image-id>
    
    Or, if you prefer to use the image name and tag, replace <image-name>:<tag> with the name and tag of the image you want to delete:
    docker rmi <image-name>:<tag>
    
  3. Delete all Docker images: If you want to delete all Docker images, you can use the following command:
    docker rmi $(docker images -q)
    
    This command uses docker images -q to list all image IDs and then passes them to docker rmi to delete them.
Please note that you cannot delete an image that is being used by an existing container. You would first need to delete or stop the container that is using the image.

containerd

To delete images in containerd, you can use the ctr command-line interface. Here are the steps:
  1. List the containerd images: Before you can delete an image, you need to know its ID or name. You can list all containerd images on your system with the ctr images ls command:
    ctr images ls
    # if no images are listed, use namespace
    ctr -n k8s.io images ls
    
    This will display a list of all containerd images along with their name and size.
  2. Delete a containerd image: Once you have the image ID or name, you can delete the image. Replace <image-name> with the name of the image you want to delete:
    ctr images rm <image-name>
    # use namespace if necessary
    ctr -n k8s.io images rm <image-name>
    
  3. Delete all containerd images: If you want to delete all containerd images, you can use the following command:
    ctr images ls -q | xargs -r ctr images rm
    # use namespace if necessary
    ctr -n k8s.io images ls -q | xargs -r ctr images rm
    
    This command uses ctr images ls -q to list all image names and then passes them to ctr images rm to delete them.
Please note that you cannot delete an image that is being used by an existing container. You would first need to delete or stop the container that is using the image.