Boot2Docker v1.3 supports the Kernel option binfmts. I also found some nice Docker images by David Weinstein on his GitHub repo.
It didn’t work straight out of the box, therefore this blog post.
- I build the data container with my own ARM Image – I just unzipped the tar file into the /data/images directory. (Step 1+2)
- Then I build the qemu-arm image, which spit out some unpleasant errors while setting up the binfmt-support (2.1.4-1) image:
1 2 | mount: permission denied update-binfmts: warning: Couldn't mount the binfmt_misc filesystem on /proc/sys/fs/binfmt_misc. |
I Ignored those errors and started the arm container:
1 2 3 4 5 | > docker run --privileged -t -i --rm --volumes-from qemu-arm_data qemu-arm [ root@7ca5a89cb6e9:/ ]$ cp /usr/bin/qemu-arm-static /data/images/usr/bin [ root@7ca5a89cb6e9:/ ]$ cd /data/images/ [ root@7ca5a89cb6e9:/data/images ]$ chroot . /bin/bash chroot: failed to run command '/bin/bash': Exec format error |
Of course it didn’t work, those warnings weren’t there just to lock pretty…
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | [ root@7ca5a89cb6e9:/chroot ]$ ll /proc/sys/fs/binfmt_misc/ total 0 dr-xr-xr-x 1 root root 0 Oct 24 20:52 ./ dr-xr-xr-x 1 root root 0 Oct 24 20:52 ../ [ root@f9f75354a44f:/data/images ]$ cat /proc/config.gz | gunzip | grep BINFMT_MISC CONFIG_BINFMT_MISC=y [ root@f9f75354a44f:/data/images ]$ mount binfmt_misc -t binfmt_misc /proc/sys/fs/binfmt_misc [ root@f9f75354a44f:/data/images ]$ mount none on / type aufs (rw,relatime,si=5a9f526cb1bae5d0) proc on /proc type proc (rw,nosuid,nodev,noexec,relatime) tmpfs on /dev type tmpfs (rw,nosuid,mode=755) shm on /dev/shm type tmpfs (rw,nosuid,nodev,noexec,relatime,size=65536k) devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=666) sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime) /dev/sda1 on /etc/resolv.conf type ext4 (rw,relatime,data=ordered) /dev/sda1 on /etc/hostname type ext4 (rw,relatime,data=ordered) /dev/sda1 on /etc/hosts type ext4 (rw,relatime,data=ordered) /dev/sda1 on /data type ext4 (rw,relatime,data=ordered) devpts on /dev/console type devpts (rw,relatime,mode=600,ptmxmode=000) /dev/sda1 on /chroot type ext4 (rw,relatime,data=ordered) binfmt_misc on /proc/sys/fs/binfmt_misc type binfmt_misc (rw,relatime) [ root@f9f75354a44f:/data/images ]$ cat /proc/sys/fs/binfmt_misc/status enabled [ root@f9f75354a44f:/data/images ]$ chroot . /bin/bash chroot: failed to run command '/bin/bash': Exec format error |
One step closer – but still not there…
1 2 3 4 5 6 7 8 9 10 11 12 13 | [ root@442c93f76831:/data/images ]$ update-binfmts --enable qemu-arm [ root@442c93f76831:/data/images ]$ ll /proc/sys/fs/binfmt_misc/ qemu-arm register status [ root@442c93f76831:/data/images ]$ cat /proc/sys/fs/binfmt_misc/qemu-arm enabled interpreter /usr/bin/qemu-arm-static flags: OC offset 0 magic 7f454c4601010100000000000000000002002800 mask ffffffffffffff00fffffffffffffffffeffffff [ root@442c93f76831:/data/images ]$ chroot . /bin/bash [root@442c93f76831 /]# uname -a Linux 442c93f76831 3.16.4-tinycore64 #1 SMP Tue Oct 14 01:10:32 UTC 2014 armv7l GNU/Linux |
Hooray! RTFM and I had enabled the STATIC qemu-arm package earlier..
Update#1:
Before you chroot into your new system, make sure to mount proc, sysfs and dev…
1 2 3 4 5 6 7 8 9 10 11 12 | [ root@43aae86b85cc:/data/images ]$ mount -t proc none /data/images/proc [ root@43aae86b85cc:/data/images ]$ mount -t sysfs none /data/images/sys [ root@43aae86b85cc:/data/images ]$ mount -o bind /dev /data/images/dev [ root@43aae86b85cc:/data/images ]$ mount -o bind /dev/pts /data/images/dev/pts [ root@43aae86b85cc:/data/images ]$ chroot . /bin/bash [root@43aae86b85cc /]# mount none on /proc type proc (rw,relatime) none on /sys type sysfs (rw,relatime) tmpfs on /dev type tmpfs (rw,nosuid,mode=755) devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=666) [root@43aae86b85cc /]# rm /etc/resolv.conf [root@43aae86b85cc /]# echo nameserver 8.8.8.8 > /etc/resolv.conf |
Update#2:
If you re-start the Docker image, enter those commands to chroot into the arm image:
1 2 3 4 5 6 7 8 9 | [ root@c94edb83d9d7:/ ]$ cd /data/images/ [ root@c94edb83d9d7:/data/images ]$ mount binfmt_misc -t binfmt_misc /proc/sys/fs/binfmt_misc [ root@c94edb83d9d7:/data/images ]$ mount -t proc none /data/images/proc [ root@c94edb83d9d7:/data/images ]$ mount -t sysfs none /data/images/sys [ root@c94edb83d9d7:/data/images ]$ mount -o bind /dev /data/images/dev [ root@c94edb83d9d7:/data/images ]$ mount -o bind /dev/pts /data/images/dev/pts [ root@c94edb83d9d7:/data/images ]$ chroot . /bin/bash [root@c94edb83d9d7 /]# uname -a Linux c94edb83d9d7 3.16.4-tinycore64 #1 SMP Tue Oct 14 01:10:32 UTC 2014 armv7l GNU/Linux |