From a5a01b5cf7ba75012f40c6d4e805cc42ba2c5142 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Thu, 8 Dec 2022 15:18:32 +0100 Subject: [PATCH] daemon/containerd: fix compat for "docker run" with image that's not present It's horrible, but some clients (such as the docker 17.03 CLI used in CI) still perform string-matching to detect that the *image* wasn't found. This requires the error to be prefixed with "No such image:". Without this prefix, the CLI prints the error message, and exits. Before this: docker run -it --rm hello-world docker: Error response from daemon: id not found. See 'docker run --help'. After this: docker run -it --rm hello-world Unable to find image 'hello-world:latest' locally faa03e786c97: Download complete ... Signed-off-by: Sebastiaan van Stijn --- daemon/containerd/image.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/daemon/containerd/image.go b/daemon/containerd/image.go index 7ad5335813e7f..3e1bf98dede69 100644 --- a/daemon/containerd/image.go +++ b/daemon/containerd/image.go @@ -213,7 +213,13 @@ func (i *ImageService) resolveImage(ctx context.Context, refOrID string, platfor if !cerrdefs.IsNotFound(err) { return containerdimages.Image{}, err } - return containerdimages.Image{}, errdefs.NotFound(errors.New("id not found")) + // Some clients (such as the docker 17.03 CLI used in CI) still + // perform string-matching to detect that the *image* wasn't found. + // This requires the error to be prefixed with "No such image:". + // Without this prefix, the CLI prints the error message, and exits. + // + // FIXME(thaJeztah): we need to fix this; if needed, gated by API version (API < X add the prefix) + return containerdimages.Image{}, errdefs.NotFound(errors.New("No such image: " + refOrID)) } if platform != nil { cs := i.client.ContentStore()