github.com/Heebron/moby@v0.0.0-20221111184709-6eab4f55faf7/daemon/containerd/image_delete.go (about) 1 package containerd 2 3 import ( 4 "context" 5 6 "github.com/containerd/containerd/images" 7 "github.com/docker/distribution/reference" 8 "github.com/docker/docker/api/types" 9 ) 10 11 // ImageDelete deletes the image referenced by the given imageRef from this 12 // daemon. The given imageRef can be an image ID, ID prefix, or a repository 13 // reference (with an optional tag or digest, defaulting to the tag name 14 // "latest"). There is differing behavior depending on whether the given 15 // imageRef is a repository reference or not. 16 // 17 // If the given imageRef is a repository reference then that repository 18 // reference will be removed. However, if there exists any containers which 19 // were created using the same image reference then the repository reference 20 // cannot be removed unless either there are other repository references to the 21 // same image or force is true. Following removal of the repository reference, 22 // the referenced image itself will attempt to be deleted as described below 23 // but quietly, meaning any image delete conflicts will cause the image to not 24 // be deleted and the conflict will not be reported. 25 // 26 // There may be conflicts preventing deletion of an image and these conflicts 27 // are divided into two categories grouped by their severity: 28 // 29 // Hard Conflict: 30 // - a pull or build using the image. 31 // - any descendant image. 32 // - any running container using the image. 33 // 34 // Soft Conflict: 35 // - any stopped container using the image. 36 // - any repository tag or digest references to the image. 37 // 38 // The image cannot be removed if there are any hard conflicts and can be 39 // removed if there are soft conflicts only if force is true. 40 // 41 // If prune is true, ancestor images will each attempt to be deleted quietly, 42 // meaning any delete conflicts will cause the image to not be deleted and the 43 // conflict will not be reported. 44 // 45 // TODO(thaJeztah): implement ImageDelete "force" options; see https://github.com/moby/moby/issues/43850 46 // TODO(thaJeztah): implement ImageDelete "prune" options; see https://github.com/moby/moby/issues/43849 47 // TODO(thaJeztah): add support for image delete using image (short)ID; see https://github.com/moby/moby/issues/43854 48 // TODO(thaJeztah): mage delete should send image "untag" events and prometheus counters; see https://github.com/moby/moby/issues/43855 49 func (i *ImageService) ImageDelete(ctx context.Context, imageRef string, force, prune bool) ([]types.ImageDeleteResponseItem, error) { 50 parsedRef, err := reference.ParseNormalizedNamed(imageRef) 51 if err != nil { 52 return nil, err 53 } 54 ref := reference.TagNameOnly(parsedRef) 55 56 err = i.client.ImageService().Delete(ctx, ref.String(), images.SynchronousDelete()) 57 if err != nil { 58 return nil, err 59 } 60 61 return []types.ImageDeleteResponseItem{{Untagged: reference.FamiliarString(parsedRef)}}, nil 62 }