docker rmi removes images by their ID.
To remove the image, you first need to list all the images to get the Image IDs, Image name and other details. By running simple command
docker images -a or
After that you make sure which image want to remove, to do that executing this simple command
docker rmi <your-image-id>. Then you can confirm that image has been removed or not by list all the images and check.
Remove multiple images
There is a way to remove more than one images at a time, when you want to remove multiple specific images. So to do that first get Image IDs simply by listing the images then execute simple followed command.
docker rmi <your-image-id> <your-image-id> ...
Write Images IDs in the command followed by the spaces between them.
Remove all images at once
To remove all images there is a simple command to do that.
docker rmi $(docker images -q)
Here in the above command, there are two command the first which execute in the
$() is shell syntax and returns the results whatever executed in that syntax. So in this
-q- is a option is used to provide to return the unique IDs,$() returns the results of image IDs and then
docker rmi removes all those images.
For More Information:
docker rm removes containers by their name or ID.
When you have Docker containers running, you first need to stop them before deleting them.
- Stop all running containers:
docker stop $(docker ps -a -q)
- Delete all stopped containers:
docker rm $(docker ps -a -q)
Remove multiple containers
You can stop and delete multiple containers by passing the commands a list of the containers you want to remove. The shell syntax
$() returns the results of whatever is executed within the brackets. So you can create your list of containers within this to be passed to the
Here is a breakdown of docker ps -a -q
docker pslist containers
-athe option to list all containers, even stopped ones. Without this, it defaults to only listing running containers
-qthe quiet option to provide only container numeric IDs, rather than a whole table of information about containers