containerd/containerd · error
failed to get image %s for container: %w
Error message
failed to get image %s for container: %w
What it means
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.
Source
Thrown at client/container.go:221
return c.client.ContainerService().Delete(ctx, c.id)
}
func (c *container) Task(ctx context.Context, attach cio.Attach) (Task, error) {
return c.loadTask(ctx, attach)
}
// Image returns the image that the container is based on
func (c *container) Image(ctx context.Context) (Image, error) {
r, err := c.get(ctx)
if err != nil {
return nil, err
}
if r.Image == "" {
return nil, fmt.Errorf("container not created from an image: %w", errdefs.ErrNotFound)
}
i, err := c.client.ImageService().Get(ctx, r.Image)
if err != nil {
return nil, fmt.Errorf("failed to get image %s for container: %w", r.Image, err)
}
return NewImage(c.client, i), nil
}
func (c *container) NewTask(ctx context.Context, ioCreate cio.Creator, opts ...NewTaskOpts) (_ Task, retErr error) {
ctx, span := tracing.StartSpan(ctx, "container.NewTask")
defer span.End()
i, err := ioCreate(c.id)
if err != nil {
return nil, err
}
defer func() {
if retErr != nil && i != nil {
i.Cancel()
i.Close()
}
}()
cfg := i.Config()View on GitHub (pinned to 4246446a2b)
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
Example fix
// before
img, err := container.Image(ctx) // fails: image was deleted
// after
img, err := client.Pull(ctx, "docker.io/library/alpine:latest")
if err == nil {
container.Image(ctx)
} Defensive patterns
Strategy: try-catch
Validate before calling
_, err := client.ImageService().Get(ctx, imgRef)
if err != nil { /* re-pull before using container.Image */ } Try / catch
img, err := container.Image(ctx)
if err != nil {
if errdefs.IsNotFound(err) {
img, err = client.Pull(ctx, ref, WithPullUnpack)
}
if err != nil { return err }
} Prevention
- Avoid deleting images that running containers reference
- Pull image and create container in the same namespace
- Re-pull images after garbage collection policies run
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- container not created from an image: %w
- runtime not found in index
- snapshotter not found in index
- snapshotter %s was not found: %w
- inspection service could not find snapshotter %s plugin
AI-assisted analysis of containerd/containerd@4246446a2b (2026-09-02).
Data as JSON: /api/errors/1c32de0bf7c90db9.
Report an issue: GitHub.