Skip to content

Docker Workflows

Dylan Cavers edited this page May 8, 2024 · 2 revisions

Usage

There is 3 basic uses for the Docker workflow in this repository that can be accessed through the docker.sh helper script. The flags for each option are also shown below.

  • Build (--build or -b) - Use Docker to compile the repository in a container. This is also used in the Github Action to ensure the repository is error free.
  • Development Environment (--dev or -d) - This is used to develop code while ensuring dependencies are correct and makes it easier to develop from platforms such as Windows or Arch Linux where dependencies may not match the ones used in the repository.
  • Cross Compile (--cross-compile or -c) - Currently supports cross compilation for the Raspberry Pi (ArmV7). This allows us to compile binaries remotely and simply copy them onto the Pi. This workflow takes advantage of Dockers multi-platform emulation support.

The options are all accessible through the docker.sh helper script. This provides different options of how to run the different workflows, such as a clean build or rebuilding the image.

The Docker images can be build directly using the command:

docker build -t IMAGE_TAG .

This must be executed in the same directory as the Dockerfile. If the Dockerfile has a name that isn't Dockerfile (e.g. Dockerfile.crosscompile) then the file must be specified using -f Dockerfile.crosscompile

To run an image, use the Docker run command. Examples of how to run interactive/non-interactive containers as well as mounting folders into the container can be found in the docker.sh file.

Cross-Compile Usage Notes

Before cross compiling, you must ensure the correct emulators are installed for the target architecture. This can be done by running the following commands:

docker run --privileged --rm tonistiigi/binfmt --install all
docker run --privileged --rm tonistiigi/binfmt --install arm64,riscv64,arm

For more info, see here.

Maintaining

To add dependencies to the Docker container, simply add them to the list of apt installs carried out in the Dockerfile. For these to be included the image will need to be rebuilt. You can also build from source in the Dockerfile if the dependency is not available through apt (as done with PahoMQTT C++).

The entry.sh script is executed by default in the container. It contains the build commands used in the build workflow.

Clone this wiki locally