Skip to main content
BlogNewsTop News

Build NCS application firmware images using Docker

By September 1, 2020No Comments

Written by Markus Tacker, Senior Engineer at Nordic Semiconductor, about a project he worked on in his free time.

This blog originally ran on Nordic’s DevZone blog. You can find more content like this here.

Getting all dependencies in place to build the sample applications in our SDK can be a challenge, and it requires to install certain version globally in the system, which might not be preferable for everyone. 

We can leverage Docker, a containerization tool, to contain the dependencies in a way that they do not affect to local system. The dependencies will be installed inside an image, which only uses disk space and we then can build the firmware inside this image

Here is an example Dockerfile for use with the current fw-nrfconnect-nrf tree.

Building the asset_tracker application with Docker

Clone the repo:

git clone https://github.com/NordicPlayground/fw-nrfconnect-nrf

Copy the Dockerfile to e.g. /tmp/Dockerfile:

wget https://raw.githubusercontent.com/coderbyheart/fw-nrfconnect-nrf-docker/saga/Dockerfile

Build the Docker image (this will take some time, but is only needed once):

cd fw-nrfconnect-nrf
docker build -t ncs -f /tmp/Dockerfile .

Now you can build the sample, and if you change the source code, you can just execute this command again.

docker run --name ncs --rm -v ${PWD}:/workdir/ncs/fw-nrfconnect-nrf ncs/bin/bash -c 'cd ncs/fw-nrfconnect-nrf/applications/asset_tracker; west build -p always -b nrf9160_pca20035ns'

The firmware file will be in applications/asset_tracker/build/zephyr/merged.hex.

Compact Example

cd /tmp
git clone https://github.com/NordicPlayground/fw-nrfconnect-nrf wget https://raw.githubusercontent.com/coderbyheart/fw-nrfconnect-nrf-docker/saga/Dockerfile cd fw-nrfconnect-nrf
docker build -t ncs -f /tmp/Dockerfile . docker run --name ncs --rm -v /tmp/fw-nrfconnect-nrf:/workdir/ncs/fw-nrfconnect-nrf ncs /bin/bash -c 'cd ncs/fw-nrfconnect-nrf/applications/asset_tracker; west build -p always -b nrf9160_pca20035ns'
ls -la applications/asset_tracker/build/zephyr/merged.hex

Docker image: coderbyheart/fw-nrfconnect-nrf-docker:latest

Note:Using a pre-build image is a convenient way to quickly build your firmware but using images from untrusted third-parties poses the risk of exposing your source code.

When using the pre-build docker image, you can skip the `docker build` step and directly run this command in your source folder to build the asset_tracker application:

docker run --name fw-nrfconnect-nrf-docker --rm -v /tmp/fw-nrfconnect-nrf:/workdir/ncs/fw-nrfconnect-nrf coderbyheart/fw-nrfconnect-nrf-docker:latest \
/bin/bash -c 'cd ncs/fw-nrfconnect-nrf/applications/asset_tracker; west build -p always -b nrf9160_pca20035ns'

Building out-of tree applications

If you maintain your application outside of the fw-nrfconnect-nrf tree (like we do with the Cat Tracker example in Bifravst), the solution works exactly the same, since west will fetch the dependencies in the same way.