{"id":"af51e3f42b6400a9","repo":"apache/kafka","slug":"docker-image-push-failed","errorCode":null,"errorMessage":"Docker image push failed","messagePattern":"Docker image push failed","errorType":"exception","errorClass":"SystemError","httpStatus":null,"severity":"error","filePath":"docker/docker_release.py","lineNumber":49,"sourceCode":"        docker_release <image> --kafka-url <kafka_url> --image-type <type>\n\n        This command will build the multiarch image of type <type> (jvm by default),\n        named <image> using <kafka_url> to download kafka and push it to the docker image name <image> provided.\n        Make sure image is in the format of <registry>/<namespace>/<image_name>:<image_tag>.\n\"\"\"\n\nfrom datetime import date\nimport argparse\n\nfrom common import execute, build_docker_image_runner\n\ndef build_push(image, kafka_url, image_type):\n    try:\n        create_builder()\n        build_docker_image_runner(f\"docker buildx build -f $DOCKER_FILE --build-arg kafka_url={kafka_url} --build-arg build_date={date.today()} --push \\\n              --platform linux/amd64,linux/arm64 --tag {image} $DOCKER_DIR\", image_type)\n    except:\n        raise SystemError(\"Docker image push failed\")\n    finally:\n        remove_builder()\n\ndef create_builder():\n    execute([\"docker\", \"buildx\", \"create\", \"--name\", \"kafka-builder\", \"--use\"])\n\ndef remove_builder():\n    execute([\"docker\", \"buildx\", \"rm\", \"kafka-builder\"])\n\nif __name__ == \"__main__\":\n    print(\"\\\n          This script will build and push docker images of apache kafka.\\n \\\n          Please ensure that image has been sanity tested before pushing the image. \\n \\\n          Please ensure you are logged in the docker registry that you are trying to push to.\")\n    parser = argparse.ArgumentParser()\n    parser.add_argument(\"image\", help=\"Dockerhub image that you want to push to (in the format <registry>/<namespace>/<image_name>:<image_tag>)\")\n    parser.add_argument(\"--image-type\", \"-type\", choices=[\"jvm\", \"native\"], default=\"jvm\", dest=\"image_type\", help=\"Image type you want to build\")\n    parser.add_argument(\"--kafka-url\", \"-u\", dest=\"kafka_url\", help=\"Kafka url to be used to download kafka binary tarball in the docker image\")","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/apache/kafka/blob/c31c9215e131f8c17e79f8901b48c13ee6aa8e7a/docker/docker_release.py#L31-L67","documentation":"Raised by build_push() in docker/docker_release.py when any exception occurs during create_builder() or build_docker_image_runner(...) with the --push flag. Like build_docker_image_runner it is a bare except: that masks the underlying failure; the finally block still calls remove_builder() to clean up the buildx instance.","triggerScenarios":"Running docker_release.py build_push(image, kafka_url, image_type); the failure can originate in create_builder() (docker buildx create), in the buildx build itself, or specifically in the --push step (registry authentication, tag format, network).","commonSituations":"Not logged in to the docker registry (docker login), image tag not in <registry>/<namespace>/<image>:<tag> format, lack of push permission on the namespace, builder 'kafka-builder' left over from a prior failed run (so create_builder fails), or registry rate-limiting during the multi-arch push.","solutions":["Run docker login <registry> with credentials that have push permission on the target namespace.","Confirm the image argument matches <registry>/<namespace>/<image_name>:<image_tag> (see docker_release.py:35,65).","Clean up any leftover builder: docker buildx rm kafka-builder, then retry.","Reproduce manually with the expanded command from docker_release.py:46-47 to see the real error (the wrapper hides it)."],"exampleFix":"# before\ntry:\n    create_builder()\n    build_docker_image_runner(f\"docker buildx build ... --push ...\", image_type)\nexcept:\n    raise SystemError(\"Docker image push failed\")\n# after (surface the underlying cause)\ntry:\n    create_builder()\n    build_docker_image_runner(f\"docker buildx build ... --push ...\", image_type)\nexcept Exception as e:\n    raise SystemError(\"Docker image push failed\") from e","handlingStrategy":"retry","validationCode":"# Verify registry login and target tag format before attempting push.\nimport re, subprocess\ndef preflight_push(image):\n    if subprocess.run([\"docker\", \"info\"], capture_output=True).returncode != 0:\n        raise RuntimeError(\"docker daemon unavailable\")\n    if subprocess.run([\"docker\", \"buildx\", \"ls\"], capture_output=True).returncode != 0:\n        raise RuntimeError(\"buildx not installed\")\n    if not re.match(r'^[\\w.-]+/[\\w.-]+/[\\w.-]+:[\\w.-]+$', image):\n        raise ValueError(f\"image must be <registry>/<namespace>/<name>:<tag>, got {image}\")","typeGuard":"# Only attempt a push if logged in to the registry and tag is well-formed.\ndef ready_to_push(image: str) -> bool:\n    import re\n    return bool(re.match(r'^[\\w.-]+/[\\w.-]+/[\\w.-]+:[\\w.-]+$', image))","tryCatchPattern":"from docker_release import build_push\nimport time\nfor attempt in range(1, 4):\n    try:\n        build_push(image, kafka_url, image_type)\n        break\n    except SystemError:\n        if attempt == 3:\n            raise\n        time.sleep(2 ** attempt)  # registry/network hiccups often clear on retry","preventionTips":["Run 'docker login <registry>' (or 'docker buildx login') before invoking build_push; the script assumes an authenticated session.","Confirm the image tag is fully qualified <registry>/<namespace>/<name>:<tag>; missing registry prefix is a common cause of push failure.","Check that you have push permission on the target namespace and that the tag is not already immutably published.","For flaky network/registry errors, wrap build_push in a bounded retry (max 3, exponential backoff) rather than a single attempt."],"tags":["python","docker","registry","buildx","release-tooling"],"analyzedSha":"c31c9215e131f8c17e79f8901b48c13ee6aa8e7a","analyzedAt":"2026-08-03T12:34:05.770Z","schemaVersion":2}