Docker - Build rpi image on Mac Docker - Build rpi image on Mac docker docker

Docker - Build rpi image on Mac


Emulating a full alternate architecture is generally very slow. QEMU is what allows you to do this on Linux and can be integrated into a Docker container.

For building, you can use QEMU User Emulation which is much quicker than full emulation. This allows your hardware to execute ARM binaries directly and is used to ease cross-compilation and cross-debugging.

First get VirtualBox and get Vagrant and install. (Or use docker-machine from the Docker Toolbox)

Setup your VM

mkdir raspbian-dockercd raspbian-dockervagrant init debian/jessie64vagrant upvagrant ssh

Now you are on your Debian Linux VM, setup the Docker host

sudo su -apt-get install qemu-user-staticcurl https://get.docker.com/ | sh

Run a raspbian environment

docker run -ti \  --volume /usr/bin/qemu-arm-static:/usr/bin/qemu-arm-static \  philipz/rpi-raspbian \  bash

And do what you need to.

Then you can docker export and docker import to move images around. You can also use the hub or setup a registry to use push/pull

The Docker Toolbox will also allow you to easily run Docker via a VirtualBox VM on mac but I've run into more troubles than it's been worth (when you have vagrant setup).


You can fork RPI's distro builder and customise for your needs: https://github.com/RPi-Distro/pi-genIt uses qemu-debootstrap on Docker, similar to as Matt's answer.

If you plan to also build Docker images for arm architecture, qemu-debootstrap won't help. In this case you can run Docker builds directly on an ARM server, such as the ones offered by Scaleway.

My CI server runs a combination of the above, to continuously build a OS image with pre-loaded armh docker images. Then, device-init takes care of loading docker exports as docker images. The downside is that device-init can take hours to pre-load the docker images, after first boot.