简体   繁体   中英

Error running docker build for arm32v7 container on amd64 linux machine: standard_init_linux.go:207

I have an amd64 linux machine that I'm using to build an arm32v7 container. When docker build encounters the first RUN command, it errors out with:

standard_init_linux.go:207: exec user process caused "no such file or directory"

This can be easily reproduced without a docker file by running docker run -it arm32v7/ubuntu:xenial on an amd64 linux host.

I've seen this complaint elsewhere, but most advice is that you need to build an arm32v7 container on an arm32v7 host. This is fairly impractical.

I've had success on Ubuntu 19.04 and 18.10 adding some architecture emulation:

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

After adding these packages, the error goes away and I can create my arm32v7 container.

But, this does NOT work for Ubuntu 18.04 or 16.04.

Is there a general solution that works everywhere?

It seems that there are some post-install steps that are failing on Ubuntu 18.04 and 16.04.

Here are a couple workarounds that solve the problem on 18.04 and 16.04.

Method 1:

git clone https://github.com/computermouth/qemu-static-conf.git
sudo mkdir -p /lib/binfmt.d
sudo cp qemu-static-conf/*.conf /lib/binfmt.d
sudo systemctl restart systemd-binfmt.service

Method 2:

sudo mkdir -p /lib/binfmt.d
sudo sh -c 'echo :qemu-arm:M::\\x7fELF\\x01\\x01\\x01\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x02\\x00\\x28\\x00:\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\xfe\\xff\\xff\\xff:/usr/bin/qemu-arm-static:F > /lib/binfmt.d/qemu-arm-static.conf'
sudo sh -c 'echo :qemu-aarch64:M::\\x7fELF\\x02\\x01\\x01\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x02\\x00\\xb7\\x00:\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\xfe\\xff\\xff\\xff:/usr/bin/qemu-aarch64-static:F > /lib/binfmt.d/qemu-aarch64-static.conf'
sudo systemctl restart systemd-binfmt.service

That works but is a layer more than necessary. I do a lot with QEMU on U18.04 and only need to do this once because recent kernels contain the binfmt_misc module (no service layer).

Note, I build my own recent QEMU because Debian/Ubuntu distros have a very old version (2.x as I recall.) One key that the maintainers missed is the --fix-binary yes field.

To install the magic ELF mapping for aarch64:

    QEMU_AARCH64_EXEC=/opt/distros/qemu-5.1.0/bin/debug/native/aarch64-linux-user/qemu-aarch64
    sudo update-binfmts \
         --package qemu-user-static \
         --install qemu-aarch64 $QEMU_AARCH64_EXEC \
         --magic '\x7f\x45\x4c\x46\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xb7\x00' \
         --mask '\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff' \
         --offset 0 \
         --credential yes \
         --fix-binary yes
    update-binfmts --display | grep 'qemu-aarch64 ' -A 7

To remove the mapping:

    sudo update-binfmts --package qemu-user-static --remove qemu-aarch64 $QEMU_AARCH_EXEC
    update-binfmts --display

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