When building Docker images on M1 Macs using Docker Desktop, users may encounter the error message "qemu-x86_64: Could not open '/lib64/ld-linux-x86-64.so.2': No such file or directory." This issue arises because Docker attempts to use an ARM64 image as the base image but later requires binaries compiled for x86_64 architecture.
The root cause of this problem is that the M1 Mac's architecture differs from traditional x86_64 architectures. While it supports emulation through qemu-x86_64, the absence of the required file "/lib64/ld-linux-x86-64.so.2" in the ARM64 base image leads to the reported error.
Counterintuitively, the solution is to explicitly specify --platform=linux/amd64 on the "FROM" line in the Dockerfile:
FROM --platform=linux/amd64 ubuntu:focal
This instructs Docker to use an x86_64 base image, ensuring that the necessary files are present during the build process. By starting from an x86_64 image, the build process can proceed without requiring emulation, resolving the file not found error.
Alternatively, users may consider building their own ARM64-based base images and manually compiling the required software within the container during build time. However, this option may be more suitable for specific scenarios where pre-built ARM64 binaries are not available.
The above is the detailed content of Why Does My Docker Build Fail with 'qemu-x86_64: Could not open '/lib64/ld-linux-x86-64.so.2'' on M1 Macs?. For more information, please follow other related articles on the PHP Chinese website!