Public | Automated Build

Last pushed: 6 days ago
Short Description
This is a Docker image for the Rust language for arm architectures (all models of Raspberry PI)
Full Description


Public trusted images available on:

This repository is used to build a Docker image based on Debian for the Rust programming language for armv6 (eg. : all models of Raspberry Pi) architectures and a few supporting tools. The image includes :

  • rustc
  • rustdoc
  • cargo
  • git
  • SSL certificates
  • build essentials
  • Linaro cross compiler
  • many libraries compiled for armv6

So it should be able to run cargo build on most projects out of the box. The path /source is a volume where you can mount a Cargo project from the host machine.

Why ?

To setup a full cross-compiling environment is complicated. You need:

  • a build toolchain for armhf architecture : not available on Debian, but easy to install on Ubuntu
  • a Rust compiler for armhf architecture : no binaries are available, so you need to compile it from sources
  • to tell Cargo how to cross compile
  • many development libraries (headers + lib) such as openssl, compiled for armv6 architecture
  • ...

After that, if you succeed, your workstation will be a real mess.

So I created this Docker image dedicated to Rust cross-compilation on armv6.


The following command will run cargo build --release with the current directory on the host shared, with Rust 'stable' channel:

docker run -it --rm \
  -v $(pwd):/source \

Rust 'target' architecture is forced to arm-unknown-linux-gnueabihf within the container (parameter target=arm-unknown-linux-gnueabihf automatically added).

If you want to run another command from within the container, add it at the end of the previous command line.
For example, to display Cargo version:

docker run -it --rm \
  -v $(pwd):/source \
  dlecan/rust-crosscompiler-arm:stable \
  cargo --version

Optimized usage

With the previous configuration, Cargo dependencies will be downloaded and compiled again and again each time you launch the Docker container.
If you want to avoid this behavior, you must persist Cargo cache folders within the container on the host. The best is to share them with the Cargo cache folders of the host.

So you can use the following command line:

docker run -it --rm \
  -v $(pwd):/source \
  -v ~/.cargo/git:/root/.cargo/git \
  -v ~/.cargo/registry:/root/.cargo/registry \

This will cache and share sources of Cargo dependencies and Rust built librairies. It assumes that your Cargo configuration is located in ~/.cargo.

Caveat: unfortunately, with configuration, ~.cargo files will be owned by root user, so you will have to chown them to be able to use Cargo in the host.

To sum up, here is the script I use, located in /usr/local/sbin/rxc (rust cross compiler):


docker run -it --rm \
  -v $(pwd):/source \
  -v ~/.cargo/git:/root/.cargo/git \
  -v ~/.cargo/registry:/root/.cargo/registry \
  dlecan/rust-crosscompiler-arm:stable "$@"

sudo chown -R `stat -c %u:%g $HOME` $(pwd) ~/.cargo

You can then rxc cargo build.

Usage with script




Docker Pull Command
Source Repository

Comments (1)
7 months ago

awesome work! Thanks