Open oalders opened 2 months ago
Does the x86_64 build work in an arm64 container?
I'm not a huge expert on Docker and how it handles different architecture, but I've got typos-v1.24.1-x86_64-unknown-linux-musl.tar.gz
root@b808aaa78716:~/dot-files# uname -a
Linux b808aaa78716 5.15.49-linuxkit #1 SMP PREEMPT Tue Sep 13 07:51:32 UTC 2022 aarch64 aarch64 aarch64 GNU/Linux
root@b808aaa78716:~/dot-files# ./typos --version
typos-cli 1.24.1
I'm quite confused. How is an x86-64 binary working in an ARM container? I don't think that in general it would make sense to fall back to x86 binaries on normal ARM platforms, like if you were running Linux on an actual ARM-powered system.
I wonder what's going on in Docker to make this work.
ChatGPT says:
Running an x86-64 binary in an ARM container involves a few key techniques:
QEMU is an open-source emulator that can translate x86-64 instructions to ARM instructions on the fly. Docker integrates with QEMU to provide this CPU emulation.
Docker supports multi-architecture images, allowing for both ARM and x86-64 binaries within a single image.
Cross-compiling the application for ARM directly avoids the need for emulation by creating ARM-native binaries.
Platforms like Docker Desktop on macOS or Windows use QEMU for emulation to run ARM containers on x86-64 hosts.
Emulation with QEMU is commonly used for running x86-64 binaries in ARM containers. For better performance, native ARM compilation or multi-architecture Docker images are preferred.
Hmm, I'm still not sure how this worked. From my reading, it seems multi-arch images (option 2), it's just a way to distribute an image that can run on different host architectures. But inside the container image you should still only be able to run the architecture provided by the host.
And for the other options, it doesn't seem like it produces a situation where you can run x86-64 binaries on an ARM host or vice versa. Here's me trying to run an arm64 image:
docker run -it --platform linux/arm64/v8 ubuntu:latest /bin/sh
Unable to find image 'ubuntu:latest' locally
latest: Pulling from library/ubuntu
Digest: sha256:ab64a8382e935382638764d8719362bb50ee418d944c1f3d26e0c99fae49a345
Status: Downloaded newer image for ubuntu:latest
exec /bin/sh: exec format error
That's what I'd expect. I know that on macOS Docker uses VMs under the hood, but I still don't understand how you produce a VM that can run both architecture's binaries!
I have to install my dot files in a bunch of slightly different scenarios, so I occasionally test installing them in a Docker container. I'm having an issue getting
ubi
to installtypos
. Not urgent or even important, but I figured I'd open an issue.My
docker-compose.yml
includesInside the container:
Would it be reasonable to fall back to
typos-v1.24.1-x86_64-unknown-linux-musl.tar.gz
in this case?