Error Encountered: "Could Not Open '/lib64/ld-linux-x86-64.so.2'
When attempting to build a Docker image on an M1 MacOS using the command docker build -t te-grafana-dashboards-toolchain --no-cache ., 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 error indicates that the specified file, which is required for the Docker build process, is not present in the container's filesystem.
Root Cause
The fundamental cause of this error is the architectural differences between M1 chips and traditional x86-64 CPUs. Docker operates natively within a Linux environment, and the specified Dockerfile is intended to be built on a Linux/AMD64 platform. However, the M1 chips utilize a different instruction set architecture (ISA) known as ARM64, which is incompatible with x86-64 code.
Solution
To resolve this issue and successfully build the Docker image on an M1 Mac, it is necessary to specify the correct platform when creating the base image.
Specifically, the following line should be added to the Dockerfile:
FROM --platform=linux/arm64 ubuntu:focal
Or
FROM --platform=linux/arm64/v8 ubuntu:focal
By setting the platform to linux/arm64, the Docker build process will utilize an ARM64-based base image, which is compatible with the M1 chip's ISA. This will ensure that the necessary file '/lib64/ld-linux-x86-64.so.2' is available in the container's filesystem and that the Docker build can proceed without errors.
The above is the detailed content of Why Does My Docker Build Fail with 'Could Not Open '/lib64/ld-linux-x86-64.so.2'' on an M1 Mac?. For more information, please follow other related articles on the PHP Chinese website!