Skip to content

Conversation

@hojooo
Copy link

@hojooo hojooo commented Sep 21, 2025

Summary

This PR fixes Docker platform handling issues that occur when building images for a platform different from the host platform. The changes ensure that platform information is properly propagated throughout the buildpack layer export and multi-architecture image inspection processes.

Related Issues

Issue Description

Two related issues were affecting users building container images with Spring Boot's buildpack integration:

  1. New arm64 macbooks fail to bootBuildImage due to incorrect platform image #46665: ARM64 Mac users failed to build AMD64 platform images due to incorrect platform handling in Docker API calls. When buildpacks needed to be downloaded from Docker Hub, the docker save command didn't include platform information, causing Docker daemon to default to the host platform (ARM64) instead of the requested platform (AMD64).
  2. Image building may fail when specifying a platform if an image has already been built with a different platform #46674: Image platform mismatch errors occurred when building images with different platforms consecutively. Users experienced failures with the message "Image platform mismatch detected" when switching between platforms without clearing Docker's cache.

Root Cause

The issues stemmed from incomplete platform information propagation in the Docker API implementation:

  • During buildpack layer export, platform information wasn't passed to the docker save command
  • Multi-architecture image inspection didn't properly respect the pulled digest, leading to platform conflicts

Changes Made

1. Respect pulled digest when inspecting multi-arch images

  • File: buildpack/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/build/Builder.java
  • Change: Modified image inspection logic to use the actual pulled digest instead of the manifest tag
  • Impact: Prevents platform mismatch errors when working with multi-architecture images

2. Respect image platform when exporting buildpack layers

  • File: buildpack/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/DockerApi.java
  • Change: Enhanced Docker save operations to include platform information
  • Impact: Ensures correct platform handling during buildpack layer export

Ensure the builder propagates the requested image platform to
DockerApi.exportLayers so Docker 1.41+ saves layers for the pulled
architecture rather than the host default. Add platform-aware tests
issue: spring-projects#46665

Signed-off-by: hojooo <ghwn5833@gmail.com>
Capture the digest emitted during the pull stream and
inspect name@digest so the newly pulled manifest is always used.
issue: spring-projects#46674.

Signed-off-by: hojooo <ghwn5833@gmail.com>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Sep 21, 2025
@hojooo
Copy link
Author

hojooo commented Oct 27, 2025

#46674 (comment)

Signed-off-by: hojooo <ghwn5833@gmail.com>
@hojooo hojooo force-pushed the fix-build-docker-image branch from 66ac80d to 174fdb3 Compare October 28, 2025 07:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: waiting-for-triage An issue we've not yet triaged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants