No Such File or Directory Error: Troubleshooting QEMU-x86_64 on ARM64 Docker Builds
When building Docker images on M1 MacOS using QEMU-x86_64, users may encounter the error "qemu-x86_64: Could not open '/lib64/ld-linux-x86-64.so.2': No such file or directory." This error occurs because the ARM64 M1 architecture does not have the x86_64 shared object library required by the Dockerfile.
To resolve this issue, the solution lies in changing the platform specified in the Dockerfile's FROM directive. Instead of using the default ARM64 platform, explicitly specify the linux/amd64 platform as follows:
FROM --platform=linux/amd64 ubuntu:20.04
This change forces Docker to use an x86_64 base image, which includes the necessary shared object libraries. As a result, the build process will attempt to install and execute code explicitly compiled for x86_64.
Alternatively, if possible, consider using an ARM64 base image and compiling software for x86_64 within the container during build time. While possibly slower due to emulation, this approach can yield increased performance when running the container on M1-based Macs.
The above is the detailed content of QEMU-x86_64 on ARM64 Docker: How to Fix 'No such file or directory' Errors?. For more information, please follow other related articles on the PHP Chinese website!