docker image rm
| Description | Remove one or more images |
|---|---|
| Usage | docker image rm [OPTIONS] IMAGE [IMAGE...] |
| Aliases An alias is a short or memorable alternative for a longer command. | docker image removedocker rmi |
Description
Removes (and un-tags) one or more images from the host node. If an image hasmultiple tags, using this command with the tag as a parameter only removes thetag. If the tag is the only one for the image, both the image and the tag areremoved.
This does not remove images from a registry. You cannot remove an image of arunning container unless you use the-f option. To see all images on a hostuse thedocker image ls command.
Options
| Option | Default | Description |
|---|---|---|
-f, --force | Force removal of the image | |
--no-prune | Do not delete untagged parents | |
--platform | API 1.50+Remove only the given platform variant. Formatted asos[/arch[/variant]] (e.g.,linux/amd64) |
Examples
You can remove an image using its short or long ID, its tag, or its digest. Ifan image has one or more tags referencing it, you must remove all of them beforethe image is removed. Digest references are removed automatically when an imageis removed by tag.
$ docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEtest1 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 fd484f19954fError: Conflict, cannot delete image fd484f19954f because it is tagged in multiple repositories, use -f to force2013/12/11 05:47:16 Error: failed to remove one or more images$ docker rmi test1:latestUntagged: test1:latest$ docker rmi test2:latestUntagged: test2:latest$ docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEtest latest fd484f19954f 23 seconds ago 7 B (virtual 4.964 MB)$ docker rmi test:latestUntagged: test:latestDeleted: fd484f19954f4920da7ff372b5067f5b7ddb2fd3830cecd17b96ea9e286ba5b8If you use the-f flag and specify the image's short or long ID, then thiscommand untags and removes all images that match the specified ID.
$ docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEtest1 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 fd484f19954fUntagged: test1:latestUntagged: test:latestUntagged: test2:latestDeleted: fd484f19954f4920da7ff372b5067f5b7ddb2fd3830cecd17b96ea9e286ba5b8An image pulled by digest has no tag associated with it:
$ docker images --digestsREPOSITORY TAG DIGEST IMAGE ID CREATED SIZElocalhost:5000/test/busybox <none> sha256:cbbf2f9a99b47fc460d422812b6a5adff7dfee951d8fa2e4a98caa0382cfbdbf 4986bf8c1536 9 weeks ago 2.43 MBTo remove an image using its digest:
$ docker rmi localhost:5000/test/busybox@sha256:cbbf2f9a99b47fc460d422812b6a5adff7dfee951d8fa2e4a98caa0382cfbdbfUntagged: localhost:5000/test/busybox@sha256:cbbf2f9a99b47fc460d422812b6a5adff7dfee951d8fa2e4a98caa0382cfbdbfDeleted: 4986bf8c15363d1c5d15512d5266f8777bfba4974ac56e3270e7760f6f0a8125Deleted: ea13149945cb6b1e746bf28032f02e9b5a793523481a0a18645fc77ad53c4ea2Deleted: df7546f9f060a2268024c8a230d8639878585defcc1bc6f79d2728a13957871bRemove specific platforms (--platform)
The--platform option allows you to specify which platform variants of theimage to remove. By default,docker image remove removes all platform variantsthat are present. Use the--platform option to specify which platform variantof the image to remove.
Removing a specific platform removes the image from all images that referencethe same content, and requires the--force option to be used. Omitting the--force option produces a warning, and the remove is canceled:
$ docker image rm --platform=linux/amd64 alpineError response from daemon: Content will be removed from all images referencing this variant. Use —-force to force delete.The platform option takes theos[/arch[/variant]] format; for example,linux/amd64 orlinux/arm64/v8. Architecture and variant are optional,and default to the daemon's native architecture if omitted.
You can pass multiple platforms either by passing the--platform flagmultiple times, or by passing a comma-separated list of platforms to remove.The following uses of this option are equivalent;
$ docker image rm --plaform linux/amd64 --platform linux/ppc64le myimage$ docker image rm --plaform linux/amd64,linux/ppc64le myimageThe following example removes thelinux/amd64 andlinux/ppc64le variantsof analpine image that contains multiple platform variants in the imagecache:
$ docker image ls --treeIMAGE ID DISK USAGE CONTENT SIZE EXTRAalpine:latest a8560b36e8b8 37.8MB 11.2MB U├─ linux/amd64 1c4eef651f65 12.1MB 3.64MB U├─ linux/arm/v6 903bfe2ae994 0B 0B├─ linux/arm/v7 9c2d245b3c01 0B 0B├─ linux/arm64/v8 757d680068d7 12.8MB 3.99MB├─ linux/386 2436f2b3b7d2 0B 0B├─ linux/ppc64le 9ed53fd3b831 12.8MB 3.58MB├─ linux/riscv64 1de5eb4a9a67 0B 0B└─ linux/s390x fe0dcdd1f783 0B 0B$ docker image --platform=linux/amd64,linux/ppc64le --force alpineDeleted: sha256:1c4eef651f65e2f7daee7ee785882ac164b02b78fb74503052a26dc061c90474Deleted: sha256:9ed53fd3b83120f78b33685d930ce9bf5aa481f6e2d165c42cbbddbeaa196f6fAfter the command completes, the given variants of thealpine image are removedfrom the image cache:
$ docker image ls --treeIMAGE ID DISK USAGE CONTENT SIZE EXTRAalpine:latest a8560b36e8b8 12.8MB 3.99MB├─ linux/amd64 1c4eef651f65 0B 0B├─ linux/arm/v6 903bfe2ae994 0B 0B├─ linux/arm/v7 9c2d245b3c01 0B 0B├─ linux/arm64/v8 757d680068d7 12.8MB 3.99MB├─ linux/386 2436f2b3b7d2 0B 0B├─ linux/ppc64le 9ed53fd3b831 0B 0B├─ linux/riscv64 1de5eb4a9a67 0B 0B└─ linux/s390x fe0dcdd1f783 0B 0B[8]ページ先頭