Docker – Build rpi image on Mac
This could be more generic and be building an image for architecture B with a machine architecture A. I currently want to create an image with lot of Python dependencies. Which take time on raspberry-pi but is faster on Mac. When I get an error at the end well need to rebuild. Is there a way to build this image on Mac and then pull it on my raspberry pi ?
2 Solutions collect form web for “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-docker cd raspbian-docker vagrant init debian/jessie64 vagrant up vagrant ssh
Now you are on your Debian Linux VM, setup the Docker host
sudo su - apt-get install qemu-user-static curl 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
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-gen
It 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.