c8d: add support for removing images by shortID#45362
Conversation
36b07d0 to
7be6b39
Compare
7be6b39 to
e57708e
Compare
Signed-off-by: Laura Brehm <laurabrehm@hey.com>
e57708e to
8df3db4
Compare
|
Ugh.. the existing logic is so confusing 😞 This PR (with containerd integration enabled): docker pull busybox
Using default tag: latest
b5d6fe071263: Download complete
ba7000206594: Download complete
3fbaf71a998b: Download complete
b50100f25006: Download complete
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
busybox latest b5d6fe071263 4 minutes ago 5.86MB
docker tag busybox b5d6fe071263
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
b5d6fe071263 latest b5d6fe071263 4 seconds ago 5.86MB
busybox latest b5d6fe071263 5 minutes ago 5.86MB
docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
busybox latest b5d6fe071263 5 minutes ago 5.86MB
docker tag busybox b5d6fe071263
docker rmi b5d6
docker rmi b5d6
Untagged: b5d6
docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
busybox latest b5d6fe071263 6 minutes ago 5.86MBwithout containerd integration docker pull busybox
Using default tag: latest
latest: Pulling from library/busybox
b50100f25006: Pull complete
Digest: sha256:b5d6fe0712636ceb7430189de28819e195e8966372edfc2d9409d79402a0dc16
Status: Downloaded newer image for busybox:latest
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
busybox latest 3fbaf71a998b 5 weeks ago 3.73MB
docker tag busybox 3fbaf71a998b
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
3fbaf71a998b latest 3fbaf71a998b 5 weeks ago 3.73MB
busybox latest 3fbaf71a998b 5 weeks ago 3.73MB
docker rmi 3fbaf71a998b
Error response from daemon: conflict: unable to delete 3fbaf71a998b (must be forced) - image is referenced in multiple repositories
docker rmi 3fba
Error response from daemon: conflict: unable to delete 3fbaf71a998b (must be forced) - image is referenced in multiple repositories
docker tag busybox 3fba
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
3fbaf71a998b latest 3fbaf71a998b 5 weeks ago 3.73MB
busybox latest 3fbaf71a998b 5 weeks ago 3.73MB
3fba latest 3fbaf71a998b 5 weeks ago 3.73MB
docker rmi 3fba
Error response from daemon: conflict: unable to delete 3fbaf71a998b (must be forced) - image is referenced in multiple repositoriesAnd now I'm wondering if that error is correct; in this case there's a full match on the image name ( moby/daemon/images/image_delete.go Lines 380 to 386 in 8012023 |
|
Right! After this PR I started digging in to bringing in all the logic from moby/daemon/images/image_delete.go Line 295 in 7624f8a Some of the logic is straightforward to port over, but some of it doesn't really map very cleanly 😅 For your question about the current implementation: docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
3fbaf71a998b latest 3fbaf71a998b 5 weeks ago 3.73MB
busybox latest 3fbaf71a998b 5 weeks ago 3.73MB
3fba latest 3fbaf71a998b 5 weeks ago 3.73MB
docker rmi 3fba
Error response from daemon: conflict: unable to delete 3fbaf71a998b (must be forced) - image is referenced in multiple repositoriesI think it's okay if this is an error since it's not clear if the user wanted to delete the image tagged I'll leave this here for now since it's still an improvement over the current situation, and probably open a PR on top of this one bringing over some of the rest of the logic. |
|
Sorry, probably should've approved the PR itself, as it does fix the immediate "short-ID" case 😅
Yes, some of te logic is too complicated, but it looks like there's also some inconsistencies, and we should properly document and verify. The general "rule" in order of priority is;
Try a couple of times to get a common prefix, then create a container with a name matching either a prefix or a full ID; docker create busybox
a0aaded9b02e5c5b6080deddef3d53eb6ea2e4d552b09ef85ad9342403181cd1
docker create busybox
ae794a02ba6d69aa12772272559f48cca9646076b9a980a04ad1eb0610d4ef2b
docker create --name ae794a02ba6d69aa12772272559f48cca9646076b9a980a04ad1eb0610d4ef2b busybox
docker create --name ae794a02ba6d busybox
docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
80b3a1d9a5cf busybox "sh" 3 seconds ago Created ae794a02ba6d
3bda3b4ea646 busybox "sh" 4 seconds ago Created ae794a02ba6d69aa12772272559f48cca9646076b9a980a04ad1eb0610d4ef2b
ae794a02ba6d busybox "sh" 11 minutes ago Created quizzical_shirley
a0aaded9b02e busybox "sh" 11 minutes ago Created intelligent_lamportA. Full ID matches the ID:docker container inspect --format='ID: {{.Id}} NAME: {{.Name}}' ae794a02ba6d69aa12772272559f48cca9646076b9a980a04ad1eb0610d4ef2b
ID: ae794a02ba6d69aa12772272559f48cca9646076b9a980a04ad1eb0610d4ef2b NAME: /quizzical_shirleyB. Inspecting the short ID returns the container named ae794a02ba6d (this is the "db" vs "db" prefix case)docker container inspect --format='ID: {{.Id}} NAME: {{.Name}}' ae794a02ba6d
ID: 80b3a1d9a5cff200d69ef350b01688224f9ee20cb19e0eb3f394780ab91fcad2 NAME: /ae794a02ba6dC. Inspecting a shorter ID-prefix produces an error;docker container inspect --format='ID: {{.Id}} NAME: {{.Name}}' a
Error response from daemon: Multiple IDs found with provided prefix: aD. Using a longer (non-ambiguous) ID-prefix:docker container inspect --format='ID: {{.Id}} NAME: {{.Name}}' ae
ID: ae794a02ba6d69aa12772272559f48cca9646076b9a980a04ad1eb0610d4ef2b NAME: /quizzical_shirleyE. Now do a
|
thaJeztah
left a comment
There was a problem hiding this comment.
LGTM 👍
I'll try to write up some tickets about the handling of ID's/Names (and the potential issue in the existing implementation)
- What I did
Added support for
docker image rmwith the shortID- How I did it
daemon/containerd/image.go-resolveDescriptor: factored out the containerd image fetching part of the code from the rest, since we need the full containerd image struct with it's name to call the containerd image service to delete it.- How to verify it
docker rmi [shortID]- Description for the changelog
- A picture of a cute animal (not mandatory but encouraged)