Docker cross-architecture builds without putting qemu-*-static in the image
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
README.md
qemu-aarch64-static.conf
qemu-alpha-static.conf
qemu-arm-static.conf
qemu-armeb-static.conf
qemu-cris-static.conf
qemu-m68k-static.conf
qemu-microblaze-static.conf
qemu-microblazeel-static.conf
qemu-mips-static.conf
qemu-mips64-static.conf
qemu-mips64el-static.conf
qemu-mipsel-static.conf
qemu-ppc-static.conf
qemu-ppc64-static.conf
qemu-ppc64abi32-static.conf
qemu-s390x-static.conf
qemu-sh4-static.conf
qemu-sh4eb-static.conf
qemu-sparc-static.conf
qemu-sparc32plus-static.conf
qemu-sparc64-static.conf

README.md

The latest versions of Docker for Windows and Docker for Mac can build non-native architecture containers. I reached out to Anil Madhavapeddy, an engineer at Docker, asking about why it wasn't the case on Linux, turns out Linux can too, there's just an issue with some distributions of qemu-user-static that's disallowing the functionality. These files enable (likely among other things) the ability to build arm32v7/* Docker images on a Linux host of a different architecture without putting qemu-*-static binaries in the image itself. (Only tested on Debian 9)

How do I know if I need them?

Run the following command:

systemctl status systemd-binfmt

If you see output like the following [note the start condition failed part]:

computermouth@debian:~$ systemctl status systemd-binfmt
● systemd-binfmt.service - Set Up Additional Binary Formats
   Loaded: loaded (/lib/systemd/system/systemd-binfmt.service; static; vendor preset: enabled)
   Active: inactive (dead) since Thu 2017-07-13 00:06:51 PDT; 5s ago
Condition: start condition failed at Thu 2017-07-13 00:06:51 PDT; 5s ago
           ├─ ConditionDirectoryNotEmpty=|/lib/binfmt.d was not met
           ├─ ConditionDirectoryNotEmpty=|/usr/lib/binfmt.d was not met
           ├─ ConditionDirectoryNotEmpty=|/usr/local/lib/binfmt.d was not met
           ├─ ConditionDirectoryNotEmpty=|/etc/binfmt.d was not met
           └─ ConditionDirectoryNotEmpty=|/run/binfmt.d was not met
     Docs: man:systemd-binfmt.service(8)
           man:binfmt.d(5)
           https://www.kernel.org/doc/Documentation/binfmt_misc.txt
  Process: 12402 ExecStart=/lib/systemd/systemd-binfmt (code=exited, status=0/SUCCESS)
 Main PID: 12402 (code=exited, status=0/SUCCESS)
      CPU: 0

...you will need the files here in one of the above directories. Personally, I've been using them in /lib/binfmt.d.

How do I install?

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

How do I test if it's working

NOTE: You will need to sudo docker below if you haven't set up the appropriate permissions.

echo -e "FROM arm32v7/debian:stretch-slim\n\nRUN echo 'it works'" > Dockerfile
docker build .

If the container succeeds to build without error, you're good to go!

Why isn't this built into Debian/Ubuntu (but it is in Fedora)?

I'm not sure, that systemd service is distributed with them out of the box, but Fedora supplies these files with their qemu-user-static package, while Debian and Ubuntu don't. I've submitted a bug report here: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=868217