By coincidence, I discovered today that two binaries compiled on my MacBook Pro 2017 using cross-compiling with two different architectures both work inside the same ubuntu:latest
docker container. Here is what happened:
I first compiled a hello-world running env GOOS=linux GOARCH=amd64 go build
, lets call this binary A. I then compiled the same hello-world program running env GOOS=linux GOARCH=arm64 go build
, lets call this binary B.
I check the md5sum of A and B and made sure that they were different binaries. I copied both of these binaries into the same docker container running ubuntu:latest
as its base, expecting B to fail when executing. However, they were both executed perfectly.
Similarly, a binary compiled using env GOOS=linux GOARCH=ppc64 go build
will not execute inside the same docker container. Does anyone know why this is?
For reference, the output of uname -sm
on my MacBook gives Darwin x86_64
. The output of uname -sm
inside my docker container running ubuntu:latest
gives Linux x86_64
It looks like this functionality was added way back in 1.13, but there's a lot more being done to make this seamless for developers that docker announced this week. From the Docker for Mac release notes:
Support for arm, aarch64, ppc64le architectures using qemu
What happening in this scenario is binfmt_misc with qemu are used to allow programs to be executed from other architectures. This requires changes on the host, which is why you often get errors trying to run commands for other architectures in Linux.
Docker only supports ppc64le
. More info here: https://docs.docker.com/docker-for-mac/multi-arch/