Run ARM binaries from within a docker container on your x86_64 system. This can assist with cross compiling ARM systems from within docker, or a variety of other tasks.
This assumes a docker host kernel with binfmt_misc support (module or built-in).
There are two pieces to this docker PoC. A data container (where we store our images) and the actual emulation system image.
- add an ARM system image to
data/images
in this directory for later mounting on loopback interface (once we're in the docker container)
- alternatively you can grab a system tarball image and just cd into that (try one of these: https://archlinuxarm.org/platforms/armv7)
-
build the data image container (
make
insidedata/
) -- this stores your system images in a separate container than the running system -
run the data container once (if you don't understand why, see https://docs.docker.com/userguide/dockervolumes/).
-
build the qemu-arm image (run
make
insideqemu-arm/
).
Basically:
pushd data && make
docker run --name qemu-arm_data --entrypoint="/bin/true" -d qemu-arm-data
popd
pushd qemu-arm
make
popd
docker run --privileged -t -i --rm --volumes-from qemu-arm_data qemu-arm
In container, make sure binfmt is mounted (mount binfmt_misc -t binfmt_misc /proc/sys/fs/binfmt_misc
)
now in the docker container shell:
If mounting a system image:
mkdir -p /chroot
mount -o loop /data/images/<your image>.bin /chroot
cd /chroot
cp /usr/bin/qemu-arm-static /chroot/usr/bin/qemu-arm-static
chroot . /bin/sh
Otherwise just cd into your system image folder, copy qemu-arm-static into
chroot/usr/bin
and then chroot . /bin/sh
.
Try running uname -a
or running some files inside your chroot.
-
Maybe your host docker kernel doesn't have binfmt_misc support. I build a custom boot2docker kernel for this here.
-
Try checking
update-binfmts --display
to see if qemu-arm-static is registered -
Make sure binfmts is mounted (
mount
) - if notmount binfmt_misc -t binfmt_misc /proc/sys/fs/binfmt_misc
- binfmt-misc - https://www.kernel.org/doc/Documentation/binfmt_misc.txt
- docker volumes - https://docs.docker.com/userguide/dockervolumes/
- https://wiki.debian.org/QemuUserEmulation
- Blog post by @neophob using this repo.