Docker is an open platform for developers and sysadmins to build, ship, and run distributed applications.

QEMU is a generic and open source machine emulator and virtualizer.

Combine Docker and QEMU to run Raspbian on X86 or AMD64 platform, and build Docker image include your program that can run on RPi (ARMv6) and RPi 2 (ARMv7).

Step 1: Install Docker & QEMU on Linux

I use Ubuntu to demo this project.

Install Docker on Ubuntu:

curl -sSL https://get.docker.com/ubuntu/ | sudo sh

Insatll QEMU on Ubuntu:

sudo apt-get install qemu-user-static

Step 2: Run Raspbian on X86

Pull RPi Raspbian image of Docker

sudo docker pull philipz/rpi-raspbian:latest

sudo docker run -it --rm -v /usr/bin/qemu-arm-static:/usr/bin/qemu-arm-static philipz/rpi-raspbian bash

Step 3: Write Once, Run Anywhere

Dockerizing any program of linux system, it can run anywhere.

In Arch Linux on RPi install Docker.

pacman -S docker

Build Docker images of your program. This is the "Hello World" example of Mono application, first run on RPi (ARMv6). Then it run on RPi 2 (ARMv7), also run on X86 finally.

So we could portable program on RPi, RPi 2, and PC by Docker.

Step 4: Example - Run RPi XRDP Application on X86

The other example is XRDP (Remote Desktop) of RPi.

sudo docker run -it --rm -p 3389:3389 -v /usr/bin/qemu-arm-static:/usr/bin/qemu-arm-static philipz/raspbian-xfce:latest bash

Then open Remote Desktop Client to connect the XRDP of RPi on X86.


<p>Hi, very interesting idea. I've recently needed to compile something for RPi2 but it took long hours. This should help, am I right?<br><br>But I have a problem. I've installed qemu-user-static on Arch Linux:<br>$ yaourt -S qemu-user-static</p><p>Then I've check /usr/bin/qemu-arm-static exists:<br>$ ls /usr/bin/qemu-arm-static<br>/usr/bin/qemu-arm-static*</p><p>But when I run docker run, I get following:<br>$ docker run -it --rm -v /usr/bin/qemu-arm-static:/usr/bin/qemu-arm-static philipz/rpi-raspbian bash</p><p>exec format errorFATA[0002] Error response from daemon: Cannot start container e9365e9e099c2615326b3f8cad3a1dcab3a77bc8b530f015a0b1b4d6df4eabae: exec format error<br><br>I'm not sure if I'm doing something wrong. Could you help me, please? :-)</p><p>$ uname -a</p><p>Linux jprokop-ntb 3.18.6-1-ARCH #1 SMP PREEMPT Sat Feb 7 08:44:05 CET 2015 x86_64 GNU/Linux</p>
<p>Sure, there are some cross-compiler examples by Docker container for RPi, like this. <a href="https://github.com/scivm/raspberry-pi-crosscompile" rel="nofollow">https://github.com/scivm/raspberry-pi-crosscompile</a></p><p>I check my qemu-arm-static version is 2.0.0, verify the version.</p><p>$ uname -a</p><p>Linux philipz 3.13.0-45-generic #74-Ubuntu SMP Tue Jan 13 19:36:28 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux</p>
<p>I tried to run it in Ubuntu 14.04 with qemu-arm-static 2.0.0 and it's running. So it seems that it could be cause by version or maybe I have something wrong in my Arch Linux...</p><p>Anyway, can you describe me what's exactly inside your container? What does the trick? In which architecture are binaries compiled in philipz/rpi-raspbian? How does work providing of /usr/bin/qemu-arm-static through volume? Does it mean that bash command is somehow run by this binary?</p><p>Thanks once again :-)</p>
<p>Hi, This philipz/rpi-raspbian is no different with others of Docker Hub RPi images. And it was auto-build from my Github project.</p><p><a href="https://github.com/philipz/docker-rpi-raspbian" rel="nofollow">https://github.com/philipz/docker-rpi-raspbian</a></p><p>So, you would pull resin/rpi-raspbian, and use the same method to run on X86 PC. But, this method only to static binary file, other dynamic linking execute file, like java or go, will response error.</p>
<p>Thank you for the link.</p><p>My version of qemu-arm is 2.2.0, can this be a problem?</p><p>Should I try to recompile .tar.xz image by ./mkimage-raspbian.sh and then create new docker image?</p><p>Thanks for help.</p>
<p>Cool tutorial, runs like a breeze!</p><p>I just used this commands to setup a new Vagrant Ubuntu box with your given ideas above:</p>curl -sSL <a href="https://get.docker.com/ubuntu/" rel="nofollow">https://get.docker.com/ubuntu/ </a>| sudo sh<br>sudo apt-get update<br>sudo apt-get install -y qemu-user-static<br>sudo usermod --groups docker vagrant <br><p>The last command grants your user &quot;vagrant&quot; to the group &quot;docker&quot;. Then you never need a &quot;sudo&quot; to run any of the docker commands! This is really handy and saves some time...</p>
<p>Thank you!!!<br>http://askubuntu.com/questions/477551/how-can-i-use-docker-without-sudo</p>
<p>This is interesting. I've never done anything with Docker or QEMU but I think I'll try in the future. </p>

About This Instructable



Bio: Docker.Taipei 共同發起人 碁峰《Docker入門與實戰》審閱者 Acer eDC, 玉山銀行資訊處, 臺北榮民總醫院 Java/Web Developer, Image Processing, Software Engineering, Algorithmic Trading, Docker
More by philipzh:Uniform Development by Docker & QEMU 
Add instructable to: