Search code examples
architecturedockerarmraspberry-pi

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 ?


Solution

  • 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 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).