hyperledger/fabric · error

docker build failed

Error message

docker build failed

What it means

This wrap fires when the actual docker build (r.DockerBuild) executed inside the builder container returns an error. The chaincode source was streamed to the builder image but compilation/packaging failed, so no binary package can be written to the tar. The docker build output (compilation errors) is typically included in the wrapped error.

Source

Thrown at core/chaincode/platforms/platforms.go:155

	if ccType == pb.ChaincodeSpec_GOLANG.String() {
		goVersion, osVersion, archVersion, err = util.ParamsImage(client)
		if err != nil {
			return errors.Wrap(err, "get params docker image failed")
		}
	}

	buildOptions, err := platform.DockerBuildOptions(path, goVersion, osVersion, archVersion)
	if err != nil {
		return errors.Wrap(err, "platform failed to create docker build options")
	}

	output := &bytes.Buffer{}
	buildOptions.InputStream = codePackage
	buildOptions.OutputStream = output

	err = r.DockerBuild(buildOptions, client)
	if err != nil {
		return errors.Wrap(err, "docker build failed")
	}

	return writeBytesToPackage("binpackage.tar", output.Bytes(), tw)
}

func writeBytesToPackage(name string, payload []byte, tw *tar.Writer) error {
	err := tw.WriteHeader(&tar.Header{
		Name: name,
		Size: int64(len(payload)),
		Mode: 0o100644,
	})
	if err != nil {
		return err
	}

	_, err = tw.Write(payload)
	if err != nil {
		return err

View on GitHub (pinned to 2736b63f8f)

Solutions

  1. Read the wrapped error output for compiler/build output from the builder container
  2. Fix compilation errors in the chaincode source and repackage
  3. Ensure the chaincode.builder image exists locally or is pullable
  4. Verify the docker daemon is healthy and has disk space
Defensive patterns

Strategy: try-catch

Validate before calling

// ensure builder image exists before building
if _, err := client.ImageInspect(context.Background(), builderImage); err != nil {
    return fmt.Errorf("builder image %s unavailable: %w", builderImage, err)
}

Try / catch

if err != nil {
    logger.Errorf("docker build failed, output: %s", output.String())
    return errors.Wrap(err, "docker build failed")
}

Prevention

When it happens

Trigger: Calling StreamDockerBuild where the builder container's build command (e.g. go build of the chaincode) exits non-zero, or the docker build itself fails (missing builder image, daemon error).

Common situations: Chaincode source that does not compile, vendor/dependency issues, a broken or missing chaincode.builder image, or docker daemon problems during chaincode install.

Related errors


AI-assisted analysis of hyperledger/fabric@2736b63f8f (2026-09-04). Data as JSON: /api/errors/dcdde1a8ddb0bde6. Report an issue: GitHub.