如何构建ARM架构Docker Engine二进制文件?dockerd编译异常求助
Let me break down what’s going wrong with your build process and walk you through how to get a full ARM64 build of all Docker components (including dockerd).
Why Your Current Commands Aren’t Working
The core issue is that your build isn’t properly propagating the ARM64 architecture settings to all components in the Docker CE build pipeline. Here’s what’s happening:
- The
dockerclient binary is successfully cross-compiled because its build logic directly respectsGOOS/GOARCHvariables. - Components like
dockerd,containerd, andrunceither rely on precompiled binaries (pulled from upstream) or their sub-build processes aren’t inheriting your architecture flags. - Your first attempt used
cross-armwhich targets 32-bit ARM, not 64-bit ARM (ARM64/aarch64), so that parameter was incorrect. Your second attempt didn’t specifyGOARCH=arm64at all, falling back to the host x86-64 architecture for most components.
Step-by-Step Fix to Build ARM64 dockerd
Follow these steps to ensure all components compile for ARM64:
Clean Existing Build Artifacts
First, clear any cached x86-64 binaries to avoid mixing architectures:make cleanRun Cross-Compilation with Explicit Architecture Flags
Use thestatictarget with explicitGOOS/GOARCHvariables, and force compilation of dependent components (instead of using precompiled x86 binaries):make static \ GOOS=linux \ GOARCH=arm64 \ DOCKER_BUILD_PKGS=static-linux \ BUILD_CONTAINERD=true \ BUILD_RUNC=trueGOOS=linux GOARCH=arm64: Tells Go and the build system to target ARM64.BUILD_CONTAINERD=true BUILD_RUNC=true: Forces the build pipeline to compilecontainerdandruncfrom source for ARM64, instead of pulling prebuilt x86 versions.
Alternative: Use the
crossTarget
Docker’s build system has a dedicatedcrosstarget for cross-platform builds, which handles most of the architecture setup automatically:make cross \ GOOS=linux \ GOARCH=arm64Verify the Build Results
After the build completes, run yourfilecommand again to confirm all binaries are ARM64:ls | xargs fileAll entries should show
ARM aarch64instead ofx86-64.
Key Notes for Future Builds
- Always set
GOARCH=arm64explicitly when targeting 64-bit ARM—cross-armis for 32-bit ARM (armhf/armv7). - Using
make cleanbefore cross-compiling prevents cached x86 binaries from being reused accidentally. - For static builds, forcing compilation of dependencies like
containerdensures they match your target architecture.
内容的提问来源于stack exchange,提问作者atline

