{"id":"240b9bbf94104f92","repo":"apache/kafka","slug":"docker-image-build-failed","errorCode":null,"errorMessage":"Docker Image Build failed","messagePattern":"Docker Image Build failed","errorType":"exception","errorClass":"SystemError","httpStatus":null,"severity":"error","filePath":"docker/common.py","lineNumber":46,"sourceCode":"    value = input(message)\n    if value == \"\":\n        raise ValueError(\"This field cannot be empty\")\n    return value\n\ndef build_docker_image_runner(command, image_type, kafka_archive=None):\n    temp_dir_path = tempfile.mkdtemp()\n    current_dir = os.path.dirname(os.path.realpath(__file__))\n    shutil.copytree(f\"{current_dir}/{image_type}\", f\"{temp_dir_path}/{image_type}\", dirs_exist_ok=True)\n    shutil.copytree(f\"{current_dir}/resources\", f\"{temp_dir_path}/{image_type}/resources\", dirs_exist_ok=True)\n    shutil.copy(f\"{current_dir}/server.properties\", f\"{temp_dir_path}/{image_type}\")\n    if kafka_archive:\n        shutil.copy(kafka_archive, f\"{temp_dir_path}/{image_type}/kafka.tgz\")\n    command = command.replace(\"$DOCKER_FILE\", f\"{temp_dir_path}/{image_type}/Dockerfile\")\n    command = command.replace(\"$DOCKER_DIR\", f\"{temp_dir_path}/{image_type}\")\n    try:\n        execute(command.split())\n    except:\n        raise SystemError(\"Docker Image Build failed\")\n    finally:\n        shutil.rmtree(temp_dir_path)\n","sourceCodeStart":28,"sourceCodeEnd":49,"githubUrl":"https://github.com/apache/kafka/blob/c31c9215e131f8c17e79f8901b48c13ee6aa8e7a/docker/common.py#L28-L49","documentation":"Raised by build_docker_image_runner() in docker/common.py when the inner execute(command.split()) call raises any exception during the 'docker buildx build' invocation. The bare except: catches everything (including KeyboardInterrupt) and re-wraps it as SystemError, which unfortunately hides the original cause because it does not chain the exception.","triggerScenarios":"Calling build_docker_image_runner(command, image_type, kafka_archive) where command contains the 'docker buildx build' template with $DOCKER_FILE/$DOCKER_DIR placeholders. Any failure during execute() — non-zero exit, missing dockerfile, failed build context copy (shutil.copytree/copy lines 36-40), or command.split() producing a malformed argv — surfaces as this generic message.","commonSituations":"Dockerfile references a missing build arg (kafka_url, build_date), kafka.tgz not found / wrong path, resources or image_type directory missing from docker/, docker buildx build failing on a platform (e.g. arm64 emulation missing), or command.split() mis-tokenizing a path with spaces.","solutions":["Temporarily wrap the call in a try/except that prints the original exception, or run the expanded docker buildx build command manually to see the real error.","Verify the image_type directory exists under docker/ (jvm or native) and contains a Dockerfile.","Verify kafka_archive (if passed) exists and is copied as kafka.tgz; check build args kafka_url / build_date resolve.","Ensure docker buildx is set up and the target platforms (amd64/arm64) are buildable."],"exampleFix":"# before\ntry:\n    execute(command.split())\nexcept:\n    raise SystemError(\"Docker Image Build failed\")\n# after (chain the real cause)\ntry:\n    execute(command.split())\nexcept Exception as e:\n    raise SystemError(\"Docker Image Build failed\") from e","handlingStrategy":"try-catch","validationCode":"# Pre-flight: docker daemon reachable, Dockerfile path exists, kafka archive present.\nimport os, subprocess\ndef preflight(image_type, kafka_archive=None):\n    if subprocess.run([\"docker\", \"info\"], capture_output=True).returncode != 0:\n        raise RuntimeError(\"docker daemon not available\")\n    if kafka_archive and not os.path.isfile(kafka_archive):\n        raise FileNotFoundError(f\"kafka archive missing: {kafka_archive}\")","typeGuard":"# Confirm the build prerequisites hold before invoking build_docker_image_runner.\ndef can_build(image_type: str, kafka_archive=None) -> bool:\n    import shutil, os\n    return (shutil.which(\"docker\") is not None\n            and subprocess.run([\"docker\", \"info\"], capture_output=True).returncode == 0\n            and (kafka_archive is None or os.path.isfile(kafka_archive)))","tryCatchPattern":"from common import build_docker_image_runner\ntry:\n    build_docker_image_runner(cmd, image_type, kafka_archive)\nexcept SystemError as e:\n    # The wrapper swallows the real cause; re-run the docker build manually to capture logs.\n    raise RuntimeError(\"Docker build failed; rerun with 'docker buildx build' to see stderr\") from e","preventionTips":["Run 'docker info' and confirm disk space before large multi-arch builds.","Pass a local, already-downloaded kafka archive so the build does not depend on a remote URL mid-build.","Replace the bare 'except:' in build_docker_image_runner with 'except Exception as e' so the original traceback survives.","Build once for a single platform (linux/amd64) first to fail fast before attempting multi-arch push builds."],"tags":["python","docker","buildx","release-tooling","error-handling"],"analyzedSha":"c31c9215e131f8c17e79f8901b48c13ee6aa8e7a","analyzedAt":"2026-08-03T12:34:05.770Z","schemaVersion":2}