docker rmi
docker rmi deletes the image based on its ID. To delete an image, you must first list all the images to get the image ID, image name and other details. Run the simple command docker images or docker images.
Then run this simple command docker rmi to see which images you want to remove. You can then check if the image has been deleted by listing and checking all the images.
Delete multiple images
If you want to delete multiple specific images, there is a way to delete multiple images at once. To do this, first list the images to get the image ID, then run a simple command.
docker rmi <your-image-id> <your-image-id> ...
Write the image ID to the command, followed by a space.
Delete all images at once
There is a simple command to delete all images. docker rmi $(docker images -q)
There are two commands in the above command. The first command is executed in the $ () shell syntax and returns the result of that syntax. So this q uses the option to return a unique ID, $ () returns the result of the image ID, and Dockerrmi removes all those images.
Detailed information:
- Docker CLI documentation: rmi
Docker rm
docker rm deletes the container based on its name or ID.
If the Docker container is running, you must first stop the container before deleting it.
- Stop all running containers: docker stop $ (docker ps a q)
- Delete all stopped containers: docker rm $ (docker ps a q)
Delete multiple containers
You can stop and delete multiple containers by specifying a list of containers to delete in the command. The shell syntax $ () returns all the results done inside the parentheses. So you can create a list of containers and pass them to the stop and rm commands.
This is a breakdown of docker ps -a -q
- dockerps list container
- -a Option to list all containers, including stopped containers. Otherwise, only running containers are listed by default.
- -q Silent option that provides only a numeric container ID, not the entire table of information about the container
It removes one or more images from the host node. If the image contains multiple tags, using the tag with this command as a parameter will remove only the tag. If the tag is the only tag in the image, both the image and the tag will be removed.
This will not delete the image from the registry. Images of running containers can only be deleted using the f option. To see all the images on the host, use the docker images command.
cases
You can delete images that contain short or long IDs, tags, or digests. If your image has one or more tags that reference it, you need to remove them all before you can delete the image. Digest references are automatically deleted when the image is deleted by tag.
$ Docker-Images
REPOSITORY
TAG
IMAGE ID
CREATED
SIZE
test1
latest
fd484f19954f
23 seconds ago
7 B (virtual 4,964 MB)
Test
Latest
fd484f19954f
23 Seconds ago
7 B (Virtual 4,964 MB)
test2
Latest
fd484f19954f
23 seconds ago
7 B (virtual 4,964 MB)
$ docker rmi fd484f19954f
Error: Conflict, image fd484f19954f cannot be deleted because it is marked in multiple repositories. Force using f
2013/12/11 05:47:16 Error: Could not delete one or more images
$ docker rmi test1: No latest
tag: test1: Latest
$ docker rmi test2: No latest
tag: test2: latest
$ docker images
repository
tag
image ID
created
size
Test
latest
fd484f19954f
23 seconds ago
7 B (virtual 4.964 MB)
$ docker rmi Test: latest
untagged: test: latest
Deleted: fd484f19954f4920da7ff372b5067f5b7ddb2fd3830cecd17b96ea9e286ba5b8
If you use the f flag to specify a short or long image ID, this command removes all images that match the specified ID.
$ Docker-Images
REPOSITORY
TAG
IMAGE ID
CREATED
SIZE
test1
latest
fd484f19954f
23 seconds ago
7 B (virtual 4,964 MB)
Test
Latest
fd484f19954f
23 Seconds ago
7 B (Virtual 4,964 MB)
test2
latest
fd484f19954f
23 seconds ago
7 B (virtual 4.964 MB)
$ docker rmi f fd484f19954f
untagged: test1: latest
Untagged: Test: Latest
No tag: test2: latest
Deleted: fd484f19954f4920da7ff372b5067f5b7ddb2fd3830cecd17b96ea9e286ba5b8
No tags are assigned to images retrieved by the digest:
$ docker images Digest
Repository
Tags
Digest
Image ID
Created
size
Local host: 5000 / test / busybox
sha256: cbbf2f9a99b47fc460d422812b6a5adff7dfee951d8fa2e4a98caa0382cfbdbf
4986bf8c1536
9 weeks ago
2.43 MB
To delete an image using the digest:
$ docker rmi localhost: 5000 / test / busybox @ sha256: cbbf2f9a99b47fc460d422812b6a5adff7dfee951d8fa2e4a98caa0382cfbdbf
Untagged: localhost: 5000 / test / busybox @ sha256: cbbf2f9a99b47fc460d422812b6a5adff7dfee951d8fa2e4a98caa0382cfbdbf
Deleted: 4986bf8c15363d1c5d15512d5266f8777bfba4974ac56e3270e7760f6f0a8125
Deleted: ea13149945cb6b1e746bf28032f02e9b5a793523481a0a18645fc77ad53c4ea2
Deleted: df7546f9f060a2268024c8a230d8639878585defcc1bc6f79d2728a13957871b
Parent command
Command description
docker Docker CLI basic commands.