apache/kafka · error · SystemError

Docker Image Build failed

Error message

Docker Image Build failed

What it means

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.

Source

Thrown at docker/common.py:46

    value = input(message)
    if value == "":
        raise ValueError("This field cannot be empty")
    return value

def build_docker_image_runner(command, image_type, kafka_archive=None):
    temp_dir_path = tempfile.mkdtemp()
    current_dir = os.path.dirname(os.path.realpath(__file__))
    shutil.copytree(f"{current_dir}/{image_type}", f"{temp_dir_path}/{image_type}", dirs_exist_ok=True)
    shutil.copytree(f"{current_dir}/resources", f"{temp_dir_path}/{image_type}/resources", dirs_exist_ok=True)
    shutil.copy(f"{current_dir}/server.properties", f"{temp_dir_path}/{image_type}")
    if kafka_archive:
        shutil.copy(kafka_archive, f"{temp_dir_path}/{image_type}/kafka.tgz")
    command = command.replace("$DOCKER_FILE", f"{temp_dir_path}/{image_type}/Dockerfile")
    command = command.replace("$DOCKER_DIR", f"{temp_dir_path}/{image_type}")
    try:
        execute(command.split())
    except:
        raise SystemError("Docker Image Build failed")
    finally:
        shutil.rmtree(temp_dir_path)

View on GitHub (pinned to c31c9215e1)

Solutions

  1. 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.
  2. Verify the image_type directory exists under docker/ (jvm or native) and contains a Dockerfile.
  3. Verify kafka_archive (if passed) exists and is copied as kafka.tgz; check build args kafka_url / build_date resolve.
  4. Ensure docker buildx is set up and the target platforms (amd64/arm64) are buildable.

Example fix

# before
try:
    execute(command.split())
except:
    raise SystemError("Docker Image Build failed")
# after (chain the real cause)
try:
    execute(command.split())
except Exception as e:
    raise SystemError("Docker Image Build failed") from e
Defensive patterns

Strategy: try-catch

Validate before calling

# Pre-flight: docker daemon reachable, Dockerfile path exists, kafka archive present.
import os, subprocess
def preflight(image_type, kafka_archive=None):
    if subprocess.run(["docker", "info"], capture_output=True).returncode != 0:
        raise RuntimeError("docker daemon not available")
    if kafka_archive and not os.path.isfile(kafka_archive):
        raise FileNotFoundError(f"kafka archive missing: {kafka_archive}")

Type guard

# Confirm the build prerequisites hold before invoking build_docker_image_runner.
def can_build(image_type: str, kafka_archive=None) -> bool:
    import shutil, os
    return (shutil.which("docker") is not None
            and subprocess.run(["docker", "info"], capture_output=True).returncode == 0
            and (kafka_archive is None or os.path.isfile(kafka_archive)))

Try / catch

from common import build_docker_image_runner
try:
    build_docker_image_runner(cmd, image_type, kafka_archive)
except SystemError as e:
    # The wrapper swallows the real cause; re-run the docker build manually to capture logs.
    raise RuntimeError("Docker build failed; rerun with 'docker buildx build' to see stderr") from e

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of apache/kafka@c31c9215e1 (2026-08-03). Data as JSON: /data/errors/240b9bbf94104f92.json. Report an issue: GitHub.