Skip to content

c8d: implement missing image delete logic#45427

Merged
thaJeztah merged 1 commit intomoby:masterfrom
laurazard:c8d-fix-incomplete-images
May 10, 2023
Merged

c8d: implement missing image delete logic#45427
thaJeztah merged 1 commit intomoby:masterfrom
laurazard:c8d-fix-incomplete-images

Conversation

@laurazard
Copy link
Copy Markdown
Member

@laurazard laurazard commented Apr 28, 2023

- Related

- What I did

Ports over all the previous image delete logic, such as:

  • Implement prune and force flags
  • Implement hard and soft image delete conflics, which represent:
    • image referenced in multiple tags (soft conflict)
    • image being used by a stopped container (soft conflict)
    • image being used by a running container (hard conflict)
  • Implement delete logic such as:
    • if deleting by reference, and there are other references to the same image, just
      delete the passed reference
    • if deleting by reference, and there is only 1 reference and the image is being used
      by a running container, throw an error if !force, or delete the reference and create
      a dangling reference otherwise
    • if deleting by imageID, and force is true, remove all tags (otherwise soft conflict)
    • if imageID, check if stopped container is using the image (soft conflict), and
      delete anyway if force
    • if imageID was passed in, check if running container is using the image (hard conflict)
    • if prune is true, and the image being deleted has dangling parents, remove them

Also implements logic to get image parents in c8d by comparing shared layers, like what @vvoland did in #45265, so that we can prune dangling parents on image delete.

- How I did it

With neovim! 👀

- How to verify it

Pull and delete a ton of different images, tag them and use them and try to delete them 😅
Compare the results, and see if they make sense.

Some examples from me:

root@d7ded31152c0:/go/src/github.com/docker/docker# docker pull bash
Using default tag: latest
e0acf0b8fb59: Download complete
13bc69df1e93: Download complete
0e841167f105: Download complete
c41833b44d91: Download complete
dc061c8e5140: Download complete
c8c412e0d7ad: Download complete
docker.io/library/bash:latest
root@d7ded31152c0:/go/src/github.com/docker/docker# docker run -dit --name foo bash
847ac95823ef2efb8839345cca85ca28f4b6cefcd32af4d37b5ebe4d16f0b624
root@d7ded31152c0:/go/src/github.com/docker/docker# docker rmi bash
Error response from daemon: conflict: unable to remove repository reference "bash:latest" (must force) - container 847ac95823ef is using its referenced image e0acf0b8fb59
root@d7ded31152c0:/go/src/github.com/docker/docker# docker tag bash bar
root@d7ded31152c0:/go/src/github.com/docker/docker# docker images
REPOSITORY   TAG       IMAGE ID       CREATED          SIZE
bar          latest    e0acf0b8fb59   2 seconds ago    24.8MB
bash         latest    e0acf0b8fb59   19 seconds ago   24.8MB
root@d7ded31152c0:/go/src/github.com/docker/docker# docker rmi e0ac
Error response from daemon: conflict: unable to delete e0acf0b8fb59 (cannot be forced) - image is being used by running container 847ac95823ef
root@d7ded31152c0:/go/src/github.com/docker/docker# docker rmi bash
Untagged: bash:latest
root@d7ded31152c0:/go/src/github.com/docker/docker# docker images
REPOSITORY   TAG       IMAGE ID       CREATED          SIZE
bar          latest    e0acf0b8fb59   35 seconds ago   24.8MB
root@d7ded31152c0:/go/src/github.com/docker/docker# docker rmi -f bar
Untagged: bar:latest
root@d7ded31152c0:/go/src/github.com/docker/docker# docker images
REPOSITORY   TAG       IMAGE ID       CREATED         SIZE
<none>       <none>    e0acf0b8fb59   4 seconds ago   24.8MB
root@d7ded31152c0:/go/src/github.com/docker/docker# docker kill foo
foo
root@d7ded31152c0:/go/src/github.com/docker/docker# docker rm foo
foo
root@d7ded31152c0:/go/src/github.com/docker/docker# docker rmi e0ac
Untagged: moby-dangling@sha256:e0acf0b8fb59c01b6a2b66de360c86bcad5c3cd114db325155970e6bab9663a0
Deleted: sha256:e0acf0b8fb59c01b6a2b66de360c86bcad5c3cd114db325155970e6bab9663a0
root@d7ded31152c0:/go/src/github.com/docker/docker#

(complains if it's the only reference and a container is using it, allows deleting if there is another reference, forcing leaves dangling image)

root@d7ded31152c0:/go/src/github.com/docker/docker# docker pull bash
Using default tag: latest
e0acf0b8fb59: Download complete
13bc69df1e93: Download complete
0e841167f105: Download complete
c8c412e0d7ad: Download complete
c41833b44d91: Download complete
dc061c8e5140: Download complete
docker.io/library/bash:latest
root@d7ded31152c0:/go/src/github.com/docker/docker# docker tag bash bar
root@d7ded31152c0:/go/src/github.com/docker/docker# docker images
REPOSITORY   TAG       IMAGE ID       CREATED         SIZE
bar          latest    e0acf0b8fb59   1 second ago    24.8MB
bash         latest    e0acf0b8fb59   6 seconds ago   24.8MB
root@d7ded31152c0:/go/src/github.com/docker/docker# docker rmi e0ac
Error response from daemon: conflict: unable to delete e0acf0b8fb59 (must be forced) - image is referenced in multiple repositories
root@d7ded31152c0:/go/src/github.com/docker/docker# docker rmi -f e0ac
Untagged: bar:latest
Untagged: bash:latest
Deleted: sha256:e0acf0b8fb59c01b6a2b66de360c86bcad5c3cd114db325155970e6bab9663a0
root@d7ded31152c0:/go/src/github.com/docker/docker# docker images
REPOSITORY   TAG       IMAGE ID   CREATED   SIZE
root@d7ded31152c0:/go/src/github.com/docker/docker#

(complains if image referenced in multiple repos, removes all and deletes with force)

- Description for the changelog

- A picture of a cute animal (not mandatory but encouraged)

image

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/images Image Service containerd-integration Issues and PRs related to containerd integration process/cherry-picked status/2-code-review

Projects

Development

Successfully merging this pull request may close these issues.

containerd integration: implement "force" option for image delete containerd integration: implement "prune" (--no-prune) option for image delete

6 participants