Home >Backend Development >Golang >Why Does Building a Dockerfile on M1 Mac Fail with 'No such file or directory' for '/lib64/ld-linux-x86-64.so.2'?
Encountering Error "No such file or directory" for '/lib64/ld-linux-x86-64.so.2' in qemu-x86_64
When attempting to build a Dockerfile on an M1 MacOS using Rancher Desktop, users may encounter the following error:
qemu-x86_64: Could not open '/lib64/ld-linux-x86-64.so.2': No such file or directory
This error stems from attempting to install and execute code compiled for x86_64 on an ARM64 (Apple Silicon) system. By default, Docker may select an ARM64 image for the platform, which lacks the necessary libraries.
Solution for M1 MacOS:
In contrast to the original poster's solution, the key to resolving this issue on M1 MacOS is to explicitly specify the platform as linux/amd64 in the FROM line of the Dockerfile. This ensures that Docker starts with a base image that includes the required libraries:
FROM --platform=linux/amd64 ubuntu:focal
With this modification, the build process will use an x86_64 image as the starting point, enabling the installation and execution of x86_64 software within the container.
Additional Considerations:
If possible, it is recommended to consider using an ARM64 base image and compiling software within the container during build time. This approach may improve performance when running the container on an M1 Mac, as it eliminates the need for emulation.
The above is the detailed content of Why Does Building a Dockerfile on M1 Mac Fail with 'No such file or directory' for '/lib64/ld-linux-x86-64.so.2'?. For more information, please follow other related articles on the PHP Chinese website!