Merge pull request #6109 from thaJeztah/image_rm_platform · docker/cli@17dc288 · GitHub
Skip to content

Commit 17dc288

Browse files
authored
Merge pull request #6109 from thaJeztah/image_rm_platform
image rm: add --platform option
2 parents f567263 + bb0ca9f commit 17dc288

3 files changed

Lines changed: 103 additions & 16 deletions

File tree

‎cli/command/image/remove.go‎

Lines changed: 23 additions & 8 deletions

‎docs/reference/commandline/image_rm.md‎

Lines changed: 75 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ Remove one or more images
99

1010
### Options
1111

12-
| Name | Type | Default | Description |
13-
|:----------------|:-------|:--------|:-------------------------------|
14-
| `-f`, `--force` | `bool` | | Force removal of the image |
15-
| `--no-prune` | `bool` | | Do not delete untagged parents |
12+
| Name | Type | Default | Description |
13+
|:--------------------------|:--------------|:--------|:-------------------------------------------------------------------------------------------------|
14+
| `-f`, `--force` | `bool` | | Force removal of the image |
15+
| `--no-prune` | `bool` | | Do not delete untagged parents |
16+
| [`--platform`](#platform) | `stringSlice` | | Remove only the given platform variant. Formatted as `os[/arch[/variant]]` (e.g., `linux/amd64`) |
1617

1718

1819
<!---MARKER_GEN_END-->
@@ -105,3 +106,73 @@ Deleted: 4986bf8c15363d1c5d15512d5266f8777bfba4974ac56e3270e7760f6f0a8125
105106
Deleted: ea13149945cb6b1e746bf28032f02e9b5a793523481a0a18645fc77ad53c4ea2
106107
Deleted: df7546f9f060a2268024c8a230d8639878585defcc1bc6f79d2728a13957871b
107108
```
109+
110+
### <a name="platform"></a> Remove specific platforms (`--platform`)
111+
112+
The `--platform` option allows you to specify which platform variants of the
113+
image to remove. By default, `docker image remove` removes all platform variants
114+
that are present. Use the `--platform` option to specify which platform variant
115+
of the image to remove.
116+
117+
Removing a specific platform removes the image from all images that reference
118+
the same content, and requires the `--force` option to be used. Omitting the
119+
`--force` option produces a warning, and the remove is canceled:
120+
121+
```console
122+
$ docker image rm --platform=linux/amd64 alpine
123+
Error response from daemon: Content will be removed from all images referencing this variant. Use —-force to force delete.
124+
```
125+
126+
The platform option takes the `os[/arch[/variant]]` format; for example,
127+
`linux/amd64` or `linux/arm64/v8`. Architecture and variant are optional,
128+
and default to the daemon's native architecture if omitted.
129+
130+
You can pass multiple platforms either by passing the `--platform` flag
131+
multiple times, or by passing a comma-separated list of platforms to remove.
132+
The following uses of this option are equivalent;
133+
134+
```console
135+
$ docker image rm --plaform linux/amd64 --platform linux/ppc64le myimage
136+
$ docker image rm --plaform linux/amd64,linux/ppc64le myimage
137+
```
138+
139+
The following example removes the `linux/amd64` and `linux/ppc64le` variants
140+
of an `alpine` image that contains multiple platform variants in the image
141+
cache:
142+
143+
```console
144+
$ docker image ls --tree
145+
146+
IMAGE ID DISK USAGE CONTENT SIZE EXTRA
147+
alpine:latest a8560b36e8b8 37.8MB 11.2MB U
148+
├─ linux/amd64 1c4eef651f65 12.1MB 3.64MB U
149+
├─ linux/arm/v6 903bfe2ae994 0B 0B
150+
├─ linux/arm/v7 9c2d245b3c01 0B 0B
151+
├─ linux/arm64/v8 757d680068d7 12.8MB 3.99MB
152+
├─ linux/386 2436f2b3b7d2 0B 0B
153+
├─ linux/ppc64le 9ed53fd3b831 12.8MB 3.58MB
154+
├─ linux/riscv64 1de5eb4a9a67 0B 0B
155+
└─ linux/s390x fe0dcdd1f783 0B 0B
156+
157+
$ docker image --platform=linux/amd64,linux/ppc64le --force alpine
158+
Deleted: sha256:1c4eef651f65e2f7daee7ee785882ac164b02b78fb74503052a26dc061c90474
159+
Deleted: sha256:9ed53fd3b83120f78b33685d930ce9bf5aa481f6e2d165c42cbbddbeaa196f6f
160+
```
161+
162+
After the command completes, the given variants of the `alpine` image are removed
163+
from the image cache:
164+
165+
```console
166+
$ docker image ls --tree
167+
168+
IMAGE ID DISK USAGE CONTENT SIZE EXTRA
169+
alpine:latest a8560b36e8b8 12.8MB 3.99MB
170+
├─ linux/amd64 1c4eef651f65 0B 0B
171+
├─ linux/arm/v6 903bfe2ae994 0B 0B
172+
├─ linux/arm/v7 9c2d245b3c01 0B 0B
173+
├─ linux/arm64/v8 757d680068d7 12.8MB 3.99MB
174+
├─ linux/386 2436f2b3b7d2 0B 0B
175+
├─ linux/ppc64le 9ed53fd3b831 0B 0B
176+
├─ linux/riscv64 1de5eb4a9a67 0B 0B
177+
└─ linux/s390x fe0dcdd1f783 0B 0B
178+
```

‎docs/reference/commandline/rmi.md‎

Lines changed: 5 additions & 4 deletions

0 commit comments

Comments
 (0)