How does Docker do automatic qemu instruction translation in Docker for Windows and Docker for Mac?

I read that the latest distributions use Hyper-V and HyperKit respectively to start up a small Alpine VM, but I can’t find information anywhere on what Docker is doing to get the arm binaries to run.

The old practice was to copy in a qemu-arm-static binary into the container before you run any binaries. This looks like it’s still the way it has to be done on Linux, but Windows and Mac are just fine. Ultimately I’m trying to get the same experience on Linux without having to add and then remove the qemu binary to/from every image.

Does docker have a method for bind mounting qemu during the build?

c@l:~/docker$ cat /boot/config-4.9.0-3-amd64 | grep BINFMT
CONFIG_BINFMT_ELF=y
CONFIG_COMPAT_BINFMT_ELF=y
CONFIG_BINFMT_SCRIPT=y
CONFIG_BINFMT_MISC=m

c@l:~/docker$ sudo modprobe binfmt_misc

c@l:~/docker$  lsmod | grep binfmt
binfmt_misc            20480  0

c@l:~/docker$ docker build .
Sending build context to Docker daemon  2.146MB
Step 1/5 : FROM arm32v7/debian:stretch-slim
stretch-slim: Pulling from arm32v7/debian
[...]
Step 2/5 : RUN apt-get -yqq update && apt-get -y --no-install-recommends install nginx-light && apt-get -y clean && rm -rf /var/lib/apt/lists/*
 ---> Running in f74203d0cae8
standard_init_linux.go:187: exec user process caused "exec format error"
The command '/bin/sh -c apt-get -yqq update && apt-get -y --no-install-recommends install nginx-light && apt-get -y clean && rm -rf /var/lib/apt/lists/*' returned a non-zero code: 1

c@l:~/docker$ docker -v 
Docker version 17.06.0-ce, build 02c1d87

c@l:~/docker$ uname -a
Linux l 4.9.0-3-amd64 #1 SMP Debian 4.9.30-2+deb9u2 (2017-06-26) x86_64 GNU/Linux

I also have binfmt-support and qemu-user-static packages installed on the host.

Using Docker for Windows or Docker for Mac, this operation just happily runs without error.

I have opened up a feature request:

Solution found, filed bug report for Debian:

https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=868217

How to fix (Debian/Ubuntu):