Commit b776706
committed
fix: Allow to untag images associated with running or paused containers by nerdctl rmi -f
In Docker, running `docker rmi -f <Image Names>` on images associated with
running or stopped containers will untag the images, leaving <none> images.
The specific behavior in Docker is as follows.
```
> docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
alpine latest 91ef0af61f39 6 weeks ago 7.8MB
> docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
fe4caab5cf42 alpine "sleep infinity" 4 minutes ago Up 4 minutes test
> docker rmi -f alpine
Untagged: alpine:latest
Untagged: alpine@sha256:beefdbd8a1da6d2915566fde36db9db0b524eb737fc57cd1367effd16dc0d06d
> docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
<none> <none> 91ef0af61f39 6 weeks ago 7.8MB
```
On the other hand, the same operation described above with nerdctl will
result in the following error.
```
> nerdctl rmi -f alpine
FATA[0000] 1 errors:
conflict: unable to delete alpine (cannot be forced) - image is being used by running container 59261bebc8113ca1ea102203137c32406742c2ec43ca3b108a314e9bfb4657fb
```
This befavior is reported in the following:
- #3454
Therefore, this commit fixes it so that `nerdctl rmi -f <Image Names>` can
be performed on images associated with running or stopped containers.
The behaviour in nerdctl after this modification is as follows.
```
> nerdctl images
REPOSITORY TAG IMAGE ID CREATED PLATFORM SIZE BLOB SIZE
alpine latest beefdbd8a1da 5 seconds ago linux/amd64 8.458MB 3.626MB
> nerdctl ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
28c9db821576 docker.io/library/alpine:latest "sleep infinity" 6 seconds ago Up alpine-28c9d
> nerdctl rmi -f alpine
Untagged: docker.io/library/alpine:latest
Untagged: sha256:beefdbd8a1da6d2915566fde36db9db0b524eb737fc57cd1367effd16dc0d06d
> nerdctl images
REPOSITORY TAG IMAGE ID CREATED PLATFORM SIZE BLOB SIZE
<none> <none> beefdbd8a1da 3 seconds ago linux/amd64 8.458MB 3.626MB
```
Signed-off-by: Hayato Kiwata <haytok@amazon.co.jp>1 parent f12f7fe commit b776706
File tree
2 files changed
+37
-16
lines changed- cmd/nerdctl/image
- pkg/cmd/image
2 files changed
+37
-16
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
35 | 39 | | |
36 | 40 | | |
37 | 41 | | |
| |||
112 | 116 | | |
113 | 117 | | |
114 | 118 | | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | 119 | | |
121 | 120 | | |
122 | 121 | | |
123 | 122 | | |
124 | 123 | | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
125 | 130 | | |
126 | 131 | | |
127 | 132 | | |
| 133 | + | |
128 | 134 | | |
129 | 135 | | |
130 | 136 | | |
131 | 137 | | |
132 | | - | |
133 | | - | |
| 138 | + | |
| 139 | + | |
134 | 140 | | |
135 | 141 | | |
136 | | - | |
| 142 | + | |
137 | 143 | | |
138 | 144 | | |
139 | 145 | | |
| |||
219 | 225 | | |
220 | 226 | | |
221 | 227 | | |
222 | | - | |
223 | | - | |
224 | | - | |
225 | | - | |
226 | | - | |
227 | 228 | | |
228 | 229 | | |
229 | 230 | | |
230 | 231 | | |
231 | 232 | | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
232 | 239 | | |
233 | 240 | | |
234 | 241 | | |
| 242 | + | |
235 | 243 | | |
236 | 244 | | |
237 | 245 | | |
238 | 246 | | |
239 | | - | |
240 | | - | |
| 247 | + | |
| 248 | + | |
241 | 249 | | |
242 | 250 | | |
243 | | - | |
| 251 | + | |
244 | 252 | | |
245 | 253 | | |
246 | 254 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
78 | 78 | | |
79 | 79 | | |
80 | 80 | | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
81 | 94 | | |
82 | 95 | | |
83 | 96 | | |
| |||
0 commit comments