{"record":{"id":"5e7c608c0bd10085","repo":"hyperledger/fabric","slug":"error-executing-build-s-s","errorCode":null,"errorMessage":"Error executing build: %s \"%s\"","messagePattern":"Error executing build: (.+?) \"(.+?)\"","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/chaincode/platforms/util/utils.go","lineNumber":138,"sourceCode":"\t// -----------------------------------------------------------------------------------\n\tcw, err := client.ContainerAttach(context.Background(), container.ID, dcli.ContainerAttachOptions{\n\t\tStream: true,\n\t\tStdout: true,\n\t\tStderr: true,\n\t\tLogs:   true,\n\t})\n\tif err != nil {\n\t\treturn fmt.Errorf(\"Error attaching to container: %s\", err)\n\t}\n\n\t// -----------------------------------------------------------------------------------\n\t// Launch the actual build, realizing the Env/Cmd specified at container creation\n\t// -----------------------------------------------------------------------------------\n\t_, err = client.ContainerStart(context.Background(), container.ID, dcli.ContainerStartOptions{})\n\tif err != nil {\n\t\tbuff, _ := io.ReadAll(cw.Reader)\n\t\tcw.Close()\n\t\treturn fmt.Errorf(\"Error executing build: %s \\\"%s\\\"\", err, string(buff))\n\t}\n\n\t// -----------------------------------------------------------------------------------\n\t// Wait for the build to complete and gather the return value\n\t// -----------------------------------------------------------------------------------\n\tresWait := client.ContainerWait(context.Background(), container.ID, dcli.ContainerWaitOptions{})\n\tvar res dcontainer.WaitResponse\n\tselect {\n\tcase res = <-resWait.Result:\n\tcase err = <-resWait.Error:\n\t\tcw.Close()\n\t\treturn fmt.Errorf(\"Error waiting for container to complete: %s\", err)\n\t}\n\n\t// Wait for stream copying to complete before accessing stdout.\n\tdefer cw.Close()\n\tbuff, _ := io.ReadAll(cw.Reader)\n\tif res.StatusCode > 0 {","sourceCodeStart":120,"sourceCodeEnd":156,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/chaincode/platforms/util/utils.go#L120-L156","documentation":"DockerBuild starts an ephemeral builder container whose Cmd compiles chaincode inside the builder image. When docker's ContainerStart API itself fails (container cannot be started, e.g. bad entrypoint/cmd or image problem), the function reads whatever the container emitted on its attached stdout/stderr and wraps both the docker error and that buffer into this error. It indicates the build process never got to run, as opposed to a build that ran and returned a non-zero exit code.","triggerScenarios":"client.ContainerStart returns an error: the builder image lacks /bin/sh or the entrypoint cannot exec, the image was removed between pull and start, the docker daemon rejects the start (e.g. runtime/OCI error), or the container ID is invalid after a failed create path.","commonSituations":"Using a minimal/slim builder image that has no shell (/bin/sh) so the wrapping command `['/bin/sh','-c',cmd]` cannot exec; broken or incompatible builder image for the host architecture (e.g. arm64 image on amd64 daemon); Docker daemon restarted or out of resources mid-build; misconfigured 'chaincode.builder' core.yaml property pointing at a non-runnable image.","solutions":["Inspect the quoted output buffer in the message: it contains the container's stdout/stderr, usually showing 'exec: /bin/sh: not found' or an OCI runtime error","Use a builder image that includes /bin/sh (e.g. a standard golang/node ccenv image) since the Cmd is always wrapped as ['/bin/sh','-c',opts.Cmd]","Verify the image matches the daemon architecture (docker image inspect <image>) and that it is present locally or pullable","Check docker daemon health (docker info / journalctl -u docker) for runtime or resource errors and restart it if needed"],"exampleFix":"// before: minimal image without a shell\nopts := DockerBuildOptions{Image: \"scratch-based-builder\", Cmd: \"go build\"}\n// after: use an image with /bin/sh so the '/bin/sh -c' wrapper can run\nopts := DockerBuildOptions{Image: \"hyperledger/fabric-ccenv:latest\", Cmd: \"go build\"}","handlingStrategy":"try-catch","validationCode":"// Verify the builder image exists and contains /bin/sh before building\nimg, err := client.ImageInspect(ctx, opts.Image)\nif err != nil { return fmt.Errorf(\"builder image %s missing: %w\", opts.Image, err) }\n// optionally: docker run --rm --entrypoint /bin/sh <img> -c 'echo ok'","typeGuard":null,"tryCatchPattern":"if err := util.DockerBuild(opts, client); err != nil {\n    if strings.Contains(err.Error(), \"Error executing build\") {\n        // parse quoted output; check for exec/sh errors and image/runtime problems\n        logger.Errorf(\"builder container failed to start: %v\", err)\n    }\n    return err\n}","preventionTips":["Always use a builder image that includes /bin/sh (the Cmd is wrapped as /bin/sh -c)","Keep opts.Image aligned with your host architecture and Fabric version","Pre-pull the image before install/instantiate so start-time surprises are reduced","Monitor docker daemon health where chaincode builds run"],"tags":["docker","container-start","chaincode-build","go"],"backgroundTag":"docker-container-start-failed","analyzedSha":"2736b63f8fd5932511d56fe68b7039d15977f7f6","analyzedAt":"2026-09-04T08:52:36.465Z","contentChangedAt":"2026-09-04T08:52:36.465Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}