{"record":{"id":"1c32de0bf7c90db9","repo":"containerd/containerd","slug":"failed-to-get-image-s-for-container-w","errorCode":null,"errorMessage":"failed to get image %s for container: %w","messagePattern":"failed to get image (.+?) for container: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"client/container.go","lineNumber":221,"sourceCode":"\treturn c.client.ContainerService().Delete(ctx, c.id)\n}\n\nfunc (c *container) Task(ctx context.Context, attach cio.Attach) (Task, error) {\n\treturn c.loadTask(ctx, attach)\n}\n\n// Image returns the image that the container is based on\nfunc (c *container) Image(ctx context.Context) (Image, error) {\n\tr, err := c.get(ctx)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tif r.Image == \"\" {\n\t\treturn nil, fmt.Errorf(\"container not created from an image: %w\", errdefs.ErrNotFound)\n\t}\n\ti, err := c.client.ImageService().Get(ctx, r.Image)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to get image %s for container: %w\", r.Image, err)\n\t}\n\treturn NewImage(c.client, i), nil\n}\n\nfunc (c *container) NewTask(ctx context.Context, ioCreate cio.Creator, opts ...NewTaskOpts) (_ Task, retErr error) {\n\tctx, span := tracing.StartSpan(ctx, \"container.NewTask\")\n\tdefer span.End()\n\ti, err := ioCreate(c.id)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tdefer func() {\n\t\tif retErr != nil && i != nil {\n\t\t\ti.Cancel()\n\t\t\ti.Close()\n\t\t}\n\t}()\n\tcfg := i.Config()","sourceCodeStart":203,"sourceCodeEnd":239,"githubUrl":"https://github.com/containerd/containerd/blob/4246446a2bf7d03837b0244118d858799393bd80/client/container.go#L203-L239","documentation":"After finding a non-empty image reference in the container metadata, container.Image fetches it from the image service; if that Get fails, the error is wrapped with the image name. The underlying cause is usually that the image was removed from the image store while the container metadata still points at it.","triggerScenarios":"container.Image(ctx) where r.Image is set but client.ImageService().Get(ctx, r.Image) returns an error (typically ErrNotFound because the image was deleted, or a transient store/DB error).","commonSituations":"Image garbage-collected or `ctr images rm`'d after container creation; connecting to a different containerd namespace/store than the one holding the image; image imported under a different name/tag.","solutions":["Re-pull or re-import the image under the exact reference stored in the container metadata (`ctr images pull <ref>` or client.Pull)","Check the namespace (`ctr -n <ns> images ls`) matches the one used when creating the container","Remove and recreate the container referencing an image that exists"],"exampleFix":"// before\nimg, err := container.Image(ctx) // fails: image was deleted\n// after\nimg, err := client.Pull(ctx, \"docker.io/library/alpine:latest\")\nif err == nil {\n    container.Image(ctx)\n}","handlingStrategy":"try-catch","validationCode":"_, err := client.ImageService().Get(ctx, imgRef)\nif err != nil { /* re-pull before using container.Image */ }","typeGuard":null,"tryCatchPattern":"img, err := container.Image(ctx)\nif err != nil {\n    if errdefs.IsNotFound(err) {\n        img, err = client.Pull(ctx, ref, WithPullUnpack)\n    }\n    if err != nil { return err }\n}","preventionTips":["Avoid deleting images that running containers reference","Pull image and create container in the same namespace","Re-pull images after garbage collection policies run"],"tags":["containerd","image","not-found"],"backgroundTag":"image-not-found","analyzedSha":"4246446a2bf7d03837b0244118d858799393bd80","analyzedAt":"2026-09-02T00:14:43.053Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}