Home > Backend Development > Golang > Why Does My Docker Build Fail with 'qemu-x86_64: Could not open '/lib64/ld-linux-x86-64.so.2'' on M1 Macs?

Why Does My Docker Build Fail with 'qemu-x86_64: Could not open '/lib64/ld-linux-x86-64.so.2'' on M1 Macs?

DDD
Release: 2024-12-17 11:15:26
Original
180 people have browsed it

Why Does My Docker Build Fail with

"qemu-x86_64: Could not open '/lib64/ld-linux-x86-64.so.2': No such file or directory" Error in Docker Build on M1 Macs

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.

Solution:

Counterintuitively, the solution is to explicitly specify --platform=linux/amd64 on the "FROM" line in the Dockerfile:

FROM --platform=linux/amd64 ubuntu:focal
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template