qemu-x86_64: Could not open '/lib64/ld-linux-x86-64.so.2': No such file or directory
Asked Answered
V

7

121

I have a Rancher Deskop(dockerd) on M1 MacOS and when I am trying to build below dockerfile I am getting an error such as below. Here is the command how I am trying to build the image docker build -t te-grafana-dashboards-toolchain --no-cache .

I tried to change the platforms but nonae of them worked for me. I am a bit lost about this platform issue for M1 but any help will be appreciated, What I am doing wrong? What might the root cause of this?

Removing intermediate container 70af516d5d6b
 ---> a69229847153
Step 5/6 : RUN GO111MODULE="on" go get github.com/jsonnet-bundler/jsonnet-bundler/cmd/jb; ln -s $(go env GOPATH)/bin/jb /usr/bin/jb
 ---> Running in 13545862fffe
qemu-x86_64: Could not open '/lib64/ld-linux-x86-64.so.2': No such file or directory
qemu-x86_64: Could not open '/lib64/ld-linux-x86-64.so.2': No such file or directory
Removing intermediate container 13545862fffe

Dockerfile

FROM --platform=linux/amd64 ubuntu:focal
RUN apt update; apt install -y curl jq build-essential python3.8 python3-pip docker-compose jsonnet bison mercurial
RUN ln -s /usr/bin/python3.8 /usr/bin/python
RUN curl -OL https://golang.org/dl/go1.17.linux-amd64.tar.gz; mkdir /etc/golang; tar -xvzf go1.17.linux-amd64.tar.gz -C /etc/golang; ln -s /etc/golang/go/bin/go /usr/bin/go; rm -f go1.17.linux-amd64.tar.gz
RUN GO111MODULE="on" go get github.com/jsonnet-bundler/jsonnet-bundler/cmd/jb; ln -s $(go env GOPATH)/bin/jb /usr/bin/jb
WORKDIR /workspace
Vesture answered 8/2, 2022 at 20:47 Comment(0)
C
236

Incidentally, in case it's helpful to another who lands here, I have the same issue on an M1 Max MacBook Pro laptop attempting to do a docker build from a company repo that should be a pretty well traveled path, but I might be the only one (it's a small company) that has an ARM64 M1 "Apple Silicon" Mac. However I found the solution (well, a solution) to my situation was exactly the opposite of the solution to the OP's, and that was to add --platform=linux/amd64 to the FROM line of the docker file.

Example:

FROM --platform=linux/amd64 ubuntu:20.04

Otherwise it was using an ARM64 image to start from without me being the wiser but then later in the Dockerfile the build attempts to install and execute code compiled for x86_64. Starting the build process by requesting the base image be linux/amd64 ends up with then the base image having /lib64/ld-linux-x86-64.so.2. This probably means everything is being emulated as x86_64 on the ARM64 CPU via qemu-x86_64 and so if you have the option to start from an ARM64 image and can compile within the container during build time any software you can't install as ARM64 binaries, it'll probably go faster when you later run the container on the M1 based Mac. I'm not able to try that myself just yet for this case.

Concentrated answered 25/3, 2022 at 0:49 Comment(10)
Exactly same problem and with docker run adding a --platform linux/amd64 solved it. I was installing arm64 go and it couldn't run. Thanks.Twodimensional
And if you use docker-compose, you can set services.service_name.platform to be "linux/amd64". Taken from #68434801Merchantman
@slowkoni, I hope you can still help out. But what if in my case is not a docker file? I'm trying to install golang on a centOS8 docker container, and I followed the steps in here: linuxize.com/post/how-to-install-go-on-centos-8 But when I get to 'go build', I get that error...Wean
@BenButterworth setting on docker-compose file works fine! thanks!Harville
Thanks. This format worked: FROM --platform=linux/amd64 ubuntu:20.04 as image_nameUndeceive
Thank you. services.service_name.platform: "linux/amd64" workedEvetta
Another way to use this without modifying the Dockerfile : docker image build --platform=linux/amd64 -t IMAGE_NAME . Note that this works with docker alternatives like podman too.Starks
It is causing qemu: uncaught target signal 11 (Segmentation fault) - core dumpedVictorinavictorine
On Mac M1, for Ubuntu 22.04/Golang 1.20.1, --platform=linux/amd64 is required. for some of the other combinations, it seemed fine without specifying the platform.Tezel
Note that it's also possible to use the same argument in the docker command itself to specify the target platform. Example: docker build --platform=linux/amd64 (source).Dulia
A
30

Modifying Dockerfile seems to be the most popular answer but you can also set the DOCKER_DEFAULT_PLATFORM environment variable to linux/amd64.

export DOCKER_DEFAULT_PLATFORM=linux/amd64

The cause seems to reside in the AArch64 image.

Arnitaarno answered 6/9, 2022 at 8:50 Comment(2)
this would be my preferred, but when set that variable (on host system), docker run can no longer find any of my images. solution to that?Conakry
This worked for me. I was trying to build the kubernetes website repo for older k8s version.Misinform
A
12

Instead of editing the Dockerfile, as suggested in this answer, or setting an environment variable, as suggested in this answer, I prefer to pass the platform as an argument to the docker build command, with the --platform flag. The command used by the OP would then be:

docker build --platform linux/amd64 -t te-grafana-dashboards-toolchain --no-cache .
Angellaangelle answered 9/1, 2023 at 13:58 Comment(0)
F
5

Provided the base image includes the target architecture, another option that might work in your case is using Docker's built-in TARGETARCH build arg. This works for me on macOS M1.

FROM ubuntu:focal
ARG TARGETARCH
RUN apt update; apt install -y curl jq build-essential python3.8 python3-pip docker-compose jsonnet bison mercurial
RUN ln -s /usr/bin/python3.8 /usr/bin/python
RUN curl -OL https://golang.org/dl/go1.17.linux-${TARGETARCH}.tar.gz; mkdir /etc/golang; tar -xvzf go1.17.linux-${TARGETARCH}.tar.gz -C /etc/golang; ln -s /etc/golang/go/bin/go /usr/bin/go; rm -f go1.17.linux-${TARGETARCH}.tar.gz
RUN GO111MODULE="on" go get github.com/jsonnet-bundler/jsonnet-bundler/cmd/jb; ln -s $(go env GOPATH)/bin/jb /usr/bin/jb
WORKDIR /workspace
Foolscap answered 7/10, 2022 at 11:28 Comment(2)
This should be the first method to try. Most of other answers rely on x86 emulation, which does come with performance overhead and potential bug. This works perfectly in my case.Sect
Great solution as it's portable across multiple environments without needing to know that the target architecture must be specified for some (all?) dependencies. Now the build steps are identical for everyone.Ulcerate
A
2

Passing following flag to C preprocessor as CPPFLAGS solved similar issue in my M1

-DPNG_ARM_NEON_OPT=0

Pass the value as env var with key CPPFLAGS to relevant service.

Alterant answered 5/6, 2022 at 5:10 Comment(1)
The needed docker run flag is -e CPPFLAGS=-DPNG_ARM_NEON_OPT=0. Without it, the error I get is npm ERR! code 1 npm ERR! path /build/explorer/node_modules/optipng-bin npm ERR! command failed npm ERR! command sh -c node lib/install.js npm ERR! compiling from source npm ERR! Command failed: /build/explorer/node_modules/optipng-bin/vendor/optipng --version npm ERR! qemu-x86_64: Could not open '/lib64/ld-linux-x86-64.so.2': No such file or directory npm ERR! npm ERR! npm ERR! optipng pre-build test failed npm ERR! Error: Command failed: /bin/sh -c make install Marion
V
1

this resolved my issue.

FROM ubuntu:focal
RUN apt update; apt install -y curl jq build-essential python3.8 python3-pip docker-compose jsonnet bison mercurial
RUN ln -s /usr/bin/python3.8 /usr/bin/python
RUN curl -OL https://golang.org/dl/go1.17.linux-arm64.tar.gz; mkdir /etc/golang; tar -xvzf go1.17.linux-arm64.tar.gz -C /etc/golang; ln -s /etc/golang/go/bin/go /usr/bin/go; rm -f go1.17.linux-arm64.tar.gz
RUN GO111MODULE="on" go get github.com/jsonnet-bundler/jsonnet-bundler/cmd/jb@latest; ln -s /root/go/bin/jb /usr/bin/jb
WORKDIR /workspace
Vesture answered 8/2, 2022 at 21:38 Comment(2)
Only the first line has been modified (it removes --platform=linux/amd64 ).Langill
I actually get this error if I remove --platform=linux/amd64 flag and not when I put it back on.Greataunt
H
1

I have a Mac M1 Max computer and encountered an error when attempting to install Camunda Platform 8 using Helm on a Kubernetes cluster running on a KIND node. The error occurred in the Camunda Operate pod. However, after changing the default image using the '--platform linux/amd64' option, I was able to start the container successfully.

Specifically, I ran the following commands:

docker pull camunda/operate:8.1.6 --platform linux/amd64
kind load docker-image --name camunda-platform-local camunda/operate:8.1.6
Haroldson answered 7/3, 2023 at 18:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.