mitchallen/pi-cross-compile (Dockerfile)

A Dockerfile to allow cross-compiling C/C++ projects in Ubuntu that will run on a Raspberry Pi.


Note that these instructions were written for a Mac.

To use this container you must pass it a local path that contains a Makefile and a project to compile. In the example below, substitute ~/MY-PROJECTS/MY-BUILD with a path to your local project. Your folder must contain a valid make file called Makefile. The make file must contain references to the Raspberry Pi specific tools that will be described below.

docker run -it -v ~/MY-PROJECTS/MY-BUILD:/build mitchallen/pi-cross-compile


If you had a root project folder called ~/raspberry and a child folder containing your make file and source code called hello you would compile it for Raspberry Pi like this:

docker run -it -v ~/raspberry/hello:/build mitchallen/pi-cross-compile

During the build process, output should be displayed in the terminal. On success, the container will exit and an executable that works on the Pi should be left in your local build directory.

You can find an example project here:

To use the example project do the following:

mkdir ~/raspberry

cd ~/raspberry

git clone --depth=1 hello

docker run -it -v ~/raspberry/hello:/build mitchallen/pi-cross-compile

On success an executable that only runs on the Raspberry Pi should be found here: ~/raspberry/hello/bin/hello. It's up to you to figure out how to get it on your Pi to run it.


This image contains a call to download Raspberry Cross Compile tools that can be found here: It places them in a folder called pitools.

The actual line is this:

git clone --progress --verbose --depth=1 pitools

To cross compile using gcc for Raspberry Pi you would need a line like this in your Makefile:


For other tools in that folder, browse here.

Running on Pi

Once your build is complete, the executable will not work on Ubuntu or a Mac. It will be up to you to copy it over to your Pi and test it.



In lieu of a formal style guide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code.

Version History

Version 0.1.3 release notes

  • Added cd command to example usage

Version 0.1.2 release notes

  • Added links to example and added usage details

Version 0.1.1 release notes

  • Fixed type-o in README

Version 0.1.0 release notes

  • Initial release