Docker rmi Command
docker rmi The command is used to delete one or more Docker images.
docker rmi The command is very useful for managing locally stored images, helping users clean up images they no longer need and free up storage space.
Syntax
docker rmi [OPTIONS] IMAGE [IMAGE...]
Parameter Description:
IMAGE: The name or ID of the image to delete. It can be an image name, image ID, or image digest.OPTIONS: Optional parameters used to control the behavior of the command.
Common options:
-a,--all-tags: When a repository name is specified, delete all images under that repository.-f,--force: Force deletion of images, even if they are in use by a container.--help: Print help information and exit.--no-prune: Do not delete dangling parent images.-q,--quiet: Quiet mode, do not show detailed information about deleted images.
Delete a single image
docker rmi ubuntu:latest
Delete the image named ubuntu with the latest tag.
** Delete multiple images**
docker rmi ubuntu:latest nginx:latest
Delete the images named ubuntu and nginx with the latest tag.
Delete multiple tags of an image
docker rmi ubuntu:latest ubuntu:18.04
Delete the latest and 18.04 tags of the ubuntu image.
** Delete all tags of an image**
docker rmi -a ubuntu
Delete all images under the ubuntu repository.
** Force delete images**
docker rmi -f ubuntu:latest
Force delete the ubuntu image with the latest tag, even if it is in use.
** Delete dangling images**
docker rmi -d
Delete all dangling images without tags.
** Quietly delete all images**
docker rmi -q $(docker images -q)
Use quiet mode to delete all images without showing information about the deleted images.
** Delete all images in a specified repository**
docker rmi -a myrepo
Delete all images under the myrepo repository.
** Delete an image and keep its child images**
docker rmi --no-prune ubuntu:latest
Delete the ubuntu:latest image but keep its child images.
Example
View existing images:
docker images
Output:
REPOSITORY TAG IMAGE ID CREATED SIZE
my_image latest d1e1b5a3a8a9 3 days ago 128MB
my_image1 latest c3a4f5a3a8b8 4 days ago 256MB
my_image2 latest a9e1d3a7c9b9 5 days ago 512MB
Delete an image:
docker rmi my_image
Output:
Untagged: my_image:latest
Deleted: sha256:d1e1b5a3a8a9...
Delete multiple images:
docker rmi my_image1 my_image2
Output:
Untagged: my_image1:latest
Deleted: sha256:c3a4f5a3a8b8...
Untagged: my_image2:latest
Deleted: sha256:a9e1d3a7c9b9...
Common Scenarios
- Clean up unused images: Delete images you no longer need to free up storage space.
- Image management: Manage and maintain the local image library, ensuring only needed images are kept.
- Force deletion: Force delete images when they are in use by containers (use with caution).
Notes
- Force delete images (use the
-foption); this may cause containers that depend on the image to fail to run, so use it with caution. - By default,
docker rmiunused parent images will be deleted; if you do not want this, you can use--no-pruneoption.
docker rmi The command is a very important tool in Docker image management. With it, users can delete images they no longer need, free up storage space, and keep the local image library tidy. Using the appropriate options, the image deletion process can be managed flexibly.
Docker Command Reference