Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker exec /bin/sh: exec format error on Arm64

Tags:

docker

arm64

My Dockerfile works on x86 machine, but fails on the machine with arm64 architecture; specifically on a1.2xlarge (an aws EC2-instance).

Error on running docker compose up -d

#0 0.462 exec /bin/sh: exec format error
------
failed to solve: executor failed running [/bin/sh -c apt-get update]: exit code: 1

Dockerfile looks like this

FROM phusion/passenger-ruby27
ENV HOME /root
RUN apt-get update

docker -v

Docker version 20.10.17, build 100c701

uname -a

Linux Ubuntu SMP Thu Jun 9 13:06:11 UTC 2022 aarch64 aarch64 aarch64 GNU/Linux

lsb_release -a

Ubuntu 20.04.4 LTS
like image 370
red-devil Avatar asked Sep 05 '25 22:09

red-devil


1 Answers

(tldr; apt install qemu-user-static)

You might need to either user docker buildx or install QEMU or possibly both.

QEMU is a free and open-source hypervisor. It emulates the machine’s processor through dynamic binary translation and provides a set of different hardware and device models for the machine, enabling it to run a variety of guest operating systems.

There are various methods to setting up QEMU, for example when running in a GitHub pipelines you can use the GitHub action setup-qemu-action

Assuming that you are on an ubuntu based system, first check what platforms your docker driver supports.

docker buildx ls
NAME/NODE DRIVER/ENDPOINT STATUS  PLATFORMS
default * docker                  
 default default         running linux/amd64, linux/386

now install qemu.

sudo apt-get install -y qemu qemu-user-static

docker buildx ls
NAME/NODE    DRIVER/ENDPOINT             STATUS  PLATFORMS
default      docker                              
  default    default                     running linux/amd64, linux/386, linux/arm64, linux/riscv64, linux/ppc64le, linux/s390x, linux/arm/v7, linux/arm/v6

Now we have added support for arm64 architecture.

like image 170
gingerbreadboy Avatar answered Sep 09 '25 10:09

gingerbreadboy