docker:images:remove_an_image
Table of Contents
Docker - Images - Remove an image
Find the image
docker images
returns:
REPOSITORY TAG IMAGE ID CREATED SIZE ubuntu 16.10 df4ba6fcd70e 36 hours ago 100.2 MB ubuntu 16.04 f753707788c5 36 hours ago 127.2 MB ubuntu latest f753707788c5 36 hours ago 127.2 MB hello-world latest c54a2cc56cbb 3 months ago 1.848 kB docker/whalesay latest 6b362a9f73eb 16 months ago 247 MB
Remove an image
docker rmi image_name
Removing images according to a pattern
You can find all the images that match a pattern using a combination of docker images and grep.
Once you're satisfied, you can delete them by using awk to pass the IDs to docker rmi.
NOTE: These utilities are not supplied by Docker and are not necessarily available on all systems:
To find the images:
docker ps -a | grep "pattern"
To remove the images:
docker images | grep "pattern" | awk '{print $1}' | xargs docker rm
Remove all images
All the Docker images on a system can be listed by adding -a to the docker images command.
Once you're sure you want to delete them all, you can add the -q flag to pass the Image ID to docker rmi:
To list the images:
docker images -a
To remove the images:
docker rmi $(docker images -a -q)
Remove dangling (unused) images
docker rmi $(docker images --filter "dangling=true" -q --no-trunc)
NOTE: The dangling=true filter finds unused images.
docker/images/remove_an_image.txt · Last modified: 2022/09/19 14:23 by peter