简体   繁体   中英

exec format error when building docker image from arm32v7 golang image

I am trying to build a docker image FROM arm32v7/golang:1.13.4-alpine which I was successfully build from a mac but when I try to build it on a linux machine, it throws an exec format error . There so many questions on exec format error but couldn't find any solution. My docker file looks like below

FROM arm32v7/golang:1.13.4-alpine as staging

RUN .....
RUN .....
RUN tar -czvf sbuild.tar.gz ./servicebuild
......
......
CMD tar -xzvf sbuild.tar.gz && ./servicebuild

It basically fails at the first command in the docker file throwing an error standard_init_linux.go:211: exec user process caused "exec format error"

Architecture of the build machine Linux x86_64 x86_64 x86_64 GNU/Linux

Is arm32v7 not supported on the above architecture? Is there any other way I could do this?

It's because Docker for Mac supports multi-CPU architecture: https://docs.docker.com/docker-for-mac/multi-arch/

As far as I know, on Linux using native Docker you don't have that. Although you might be able to do it by installing extra software. Checkout this post for example: https://medium.com/@artur.klauser/building-multi-architecture-docker-images-with-buildx-27d80f7e2408

You need to enable execution of different multi-architecture containers by QEMU and binfmt_misc.

In recent distro this can be simply done by running:

apt-get install qemu-user-static

If this doesn't work for you, you can execute:

docker run --rm --privileged multiarch/qemu-user-static --reset --persistent yes --credential yes

Note that this may reconfigure any existing binfmt_misc setup that you have. See https://github.com/multiarch/qemu-user-static for more detail.

This information is available in one alpine repositories README but not on the wiki as far as I know: https://gitlab.alpinelinux.org/alpine/docker-abuild#configure-multi-arch-support

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM