https://github.com/rolandjitsu/raspi-cross
Cross-compile for Raspberry Pi with Docker
https://github.com/rolandjitsu/raspi-cross
cross-compilation docker raspberry-pi
Last synced: about 2 months ago
JSON representation
Cross-compile for Raspberry Pi with Docker
- Host: GitHub
- URL: https://github.com/rolandjitsu/raspi-cross
- Owner: rolandjitsu
- License: mit
- Created: 2020-10-01T04:00:15.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-10-04T07:08:29.000Z (over 5 years ago)
- Last Synced: 2026-03-30T07:59:12.097Z (2 months ago)
- Topics: cross-compilation, docker, raspberry-pi
- Language: C
- Homepage: https://rolandsdev.blog/cross-compile-for-raspberry-pi-with-docker
- Size: 10.7 KB
- Stars: 4
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Raspi Cross
> Cross-compile for Raspberry Pi with Docker.
[](https://github.com/rolandjitsu/raspi-cross/actions?query=workflow%3ATest)
## Prerequisites
Install the following tools:
* [Docker](https://docs.docker.com/engine) >= `19.03.13`
* [buildx](https://github.com/docker/buildx#installing) >= `v0.4.1`
## Setup Docker
Check current builder instances:
```bash
docker buildx ls
```
If you see an instance that uses the `docker` driver, switch to it (it's usually the `default`):
```
docker buildx use
```
Otherwise, create a builder:
```bash
docker buildx create --name my-builder --driver docker --use
```
**NOTE**: You cannot create more than one instance using the `docker` driver.
Then inspect and bootstrap it:
```bash
docker buildx inspect --bootstrap
```
## Setup Base Images
Prepare the base cross-compilation image:
```bash
docker buildx build -f Dockerfile.cross --tag cross-stretch .
```
**NOTE**: By default, the image is going to be available to use on the host as `cross-stretch`. If `docker images` doesn't show it, add the `--load` flag when building.
*P.S.* To bust the cache, use `--no-cache`.
Prepare the base image w/ some common libs usually available on the Pi:
```bash
docker buildx build -f Dockerfile.cross-pi --tag cross-pi .
```
## Compile
Compile the `hello` binary:
```bash
docker buildx build -f Dockerfile.hello -o type=local,dest=./bin .
```
Compile the `hello-pi` binary:
```bash
docker buildx build -f Dockerfile.hello-pi -o type=local,dest=./bin .
```
## Bake
To make things easier, you can use the [bake](https://github.com/docker/buildx#buildx-bake-options-target) command.
To setup the base image:
```bash
docker buildx bake cross-stretch
```
To setup the base image w/ goodies:
```bash
docker buildx bake cross-pi
```
To compile the binaries:
```bash
docker buildx bake
```
*P.S.* To bust the cache, you can use `--no-cache`.
## Learning Material
* [Docker Buildx](https://docs.docker.com/buildx/working-with-buildx/)
* [Getting started with Docker for ARM on Linux](https://www.docker.com/blog/getting-started-with-docker-for-arm-on-linux/)
* [Leverage multi-CPU Architectures](https://docs.docker.com/docker-for-mac/multi-arch/)
* [Best practices for writing Dockerfiles](https://docs.docker.com/develop/develop-images/dockerfile_best-practices/)