├── .github └── workflows │ └── docker-publish.yml ├── Dockerfile ├── Dockerfile.alpine ├── LICENSE └── README.md /.github/workflows/docker-publish.yml: -------------------------------------------------------------------------------- 1 | name: Zephyr development container 2 | 3 | on: 4 | push: 5 | branches: [ main ] 6 | 7 | jobs: 8 | build: 9 | runs-on: ubuntu-latest 10 | 11 | permissions: 12 | contents: read 13 | packages: write 14 | id-token: write 15 | 16 | strategy: 17 | matrix: 18 | sdk: [0.16.4] 19 | tool: [ 20 | { prefix: "aarch64", suffix: "-zephyr-elf"}, 21 | { prefix: "arc64", suffix: "-zephyr-elf"}, 22 | { prefix: "arc", suffix: "-zephyr-elf"}, 23 | { prefix: "arm", suffix: "-zephyr-eabi"}, 24 | { prefix: "microblazeel", suffix: "-zephyr-elf"}, 25 | { prefix: "mips", suffix: "-zephyr-elf"}, 26 | { prefix: "nios2", suffix: "-zephyr-elf"}, 27 | { prefix: "riscv64", suffix: "-zephyr-elf"}, 28 | { prefix: "sparc", suffix: "-zephyr-elf"}, 29 | { prefix: "x86_64", suffix: "-zephyr-elf"}, 30 | { prefix: "xtensa-espressif_esp32", suffix: "_zephyr-elf"}, 31 | { prefix: "xtensa-espressif_esp32s2", suffix: "_zephyr-elf"}, 32 | { prefix: "xtensa-espressif_esp32s3", suffix: "_zephyr-elf"}, 33 | { prefix: "xtensa-intel_ace15_mtpm", suffix: "_zephyr-elf"}, 34 | { prefix: "xtensa-intel_tgl_adsp", suffix: "_zephyr-elf"}, 35 | { prefix: "xtensa-nxp_imx_adsp", suffix: "_zephyr-elf"}, 36 | { prefix: "xtensa-nxp_imx8m_adsp", suffix: "_zephyr-elf"}, 37 | { prefix: "xtensa-nxp_imx8ulp_adsp", suffix: "_zephyr-elf"}, 38 | { prefix: "xtensa-sample_controller", suffix: "_zephyr-elf"}, 39 | { prefix: "xtensa-mt8195_adsp", suffix: "_zephyr-elf"}, 40 | { prefix: "nxp_adsp_rt500", suffix: "" }, 41 | { prefix: "qemu_xtensa_dc233c", suffix: ""} 42 | ] 43 | 44 | steps: 45 | - name: Checkout repository 46 | uses: actions/checkout@v4 47 | 48 | - name: Setup Docker buildx 49 | uses: docker/setup-buildx-action@v3 50 | 51 | - name: Log into GitHub Container Registry 52 | if: github.event_name != 'pull_request' 53 | uses: docker/login-action@v3 54 | with: 55 | registry: ghcr.io 56 | username: ${{ github.actor }} 57 | password: ${{ secrets.GITHUB_TOKEN }} 58 | 59 | - name: Build and push Docker image 60 | id: build-and-push 61 | uses: docker/build-push-action@v5 62 | with: 63 | context: . 64 | push: ${{ github.event_name != 'pull_request' }} 65 | tags: ghcr.io/${{ github.actor }}/zephyr:${{ matrix.tool.prefix }}-${{ matrix.sdk }}sdk 66 | build-args: | 67 | ZEPHYR_SDK_VERSION=${{ matrix.sdk }} 68 | TOOLCHAIN=${{ matrix.tool.prefix }}${{ matrix.tool.suffix }} 69 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM debian:stable-slim 2 | 3 | ARG ZEPHYR_SDK_VERSION=0.16.4 4 | ARG ZEPHYR_SDK_INSTALL_DIR=/opt/toolchains/zephyr-sdk-${ZEPHYR_SDK_VERSION} 5 | ARG ZEPHYR_SDK_TOOLCHAINS="-t arm-zephyr-eabi" 6 | 7 | # OS dependencies and packages 8 | 9 | RUN \ 10 | apt-get -y update \ 11 | && apt-get -y install --no-install-recommends \ 12 | ca-certificates \ 13 | cmake \ 14 | device-tree-compiler \ 15 | git \ 16 | ninja-build \ 17 | && apt-get clean \ 18 | && rm -rf /var/lib/apt/lists/* 19 | 20 | # Zephyr SDK 21 | 22 | RUN \ 23 | export sdk_file_name="zephyr-sdk-${ZEPHYR_SDK_VERSION}_linux-$(uname -m)_minimal.tar.xz" \ 24 | && apt-get -y update \ 25 | && apt-get -y install --no-install-recommends \ 26 | wget \ 27 | xz-utils \ 28 | && wget -q "https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v${ZEPHYR_SDK_VERSION}/${sdk_file_name}" \ 29 | && mkdir -p ${ZEPHYR_SDK_INSTALL_DIR} \ 30 | && tar -xvf ${sdk_file_name} -C ${ZEPHYR_SDK_INSTALL_DIR} --strip-components=1 \ 31 | && ${ZEPHYR_SDK_INSTALL_DIR}/setup.sh -c ${ZEPHYR_SDK_TOOLCHAINS} \ 32 | && rm ${sdk_file_name} \ 33 | && apt-get remove -y --purge \ 34 | wget \ 35 | xz-utils \ 36 | && apt-get clean \ 37 | && rm -rf /var/lib/apt/lists/* 38 | 39 | # Python 40 | 41 | ENV VIRTUAL_ENV=/opt/venv 42 | RUN \ 43 | apt-get -y update \ 44 | && apt-get -y install --no-install-recommends \ 45 | python3 \ 46 | python3-pip \ 47 | python3-venv \ 48 | && python3 -m venv $VIRTUAL_ENV 49 | ENV PATH="$VIRTUAL_ENV/bin:$PATH" 50 | 51 | # West 52 | 53 | RUN pip install --no-cache-dir wheel west -------------------------------------------------------------------------------- /Dockerfile.alpine: -------------------------------------------------------------------------------- 1 | FROM alpine:latest AS base 2 | 3 | FROM base AS west 4 | 5 | RUN \ 6 | apk add --no-cache \ 7 | gcc \ 8 | musl-dev \ 9 | python3 \ 10 | python3-dev \ 11 | py3-pip \ 12 | py3-wheel \ 13 | && pip3 install west \ 14 | && apk del --purge \ 15 | gcc \ 16 | musl-dev \ 17 | python3-dev \ 18 | py3-pip \ 19 | py3-wheel 20 | 21 | FROM west AS python 22 | 23 | ARG ZEPHYR_VERSION=v3.2.0 24 | ENV ZEPHYR_VERSION=${ZEPHYR_VERSION} 25 | 26 | RUN \ 27 | apk add --no-cache \ 28 | gcc \ 29 | linux-headers \ 30 | musl-dev \ 31 | python3 \ 32 | python3-dev \ 33 | py3-pip \ 34 | py3-wheel \ 35 | && pip3 install \ 36 | -r https://raw.githubusercontent.com/zephyrproject-rtos/zephyr/${ZEPHYR_VERSION}/scripts/requirements-base.txt \ 37 | && pip3 install cmake \ 38 | && apk del --purge \ 39 | gcc \ 40 | linux-headers \ 41 | musl-dev \ 42 | python3-dev \ 43 | py3-pip \ 44 | py3-wheel 45 | 46 | FROM python AS sdk 47 | 48 | ARG ARCHITECTURE=x86_64 49 | ARG ZEPHYR_SDK_VERSION=0.16.0 50 | ARG ZEPHYR_SDK_INSTALL_DIR=/opt/zephyr-sdk 51 | ARG TOOLCHAIN=arm-zephyr-eabi 52 | 53 | RUN \ 54 | export sdk_file_name="zephyr-sdk-${ZEPHYR_SDK_VERSION}_linux-$(uname -m)_minimal.tar.xz" \ 55 | && apk add --no-cache \ 56 | bash \ 57 | dtc \ 58 | gcompat \ 59 | git \ 60 | ninja \ 61 | py3-pip \ 62 | wget \ 63 | xz \ 64 | && wget -q "https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v${ZEPHYR_SDK_VERSION}/${sdk_file_name}" \ 65 | && mkdir -p ${ZEPHYR_SDK_INSTALL_DIR} \ 66 | && tar -xvf ${sdk_file_name} -C ${ZEPHYR_SDK_INSTALL_DIR} --strip-components=1 \ 67 | && ${ZEPHYR_SDK_INSTALL_DIR}/setup.sh -t ${TOOLCHAIN} \ 68 | && rm ${sdk_file_name} \ 69 | && apk del --purge \ 70 | bash \ 71 | wget \ 72 | xz -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Jonathan Beri 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | > [!caution] 2 | > This project is moving to a new organization called [Embedded Containers](https://github.com/embeddedcontainers). This repo will no longer be updated and new images will not be built moving forward. Previous images will remain hosted for some time. Migrate to https://github.com/embeddedcontainers/zephyr ASAP. 3 | 4 | # Docker containers for the Zephyr RTOS 5 | 6 | [![Dev Container](https://github.com/beriberikix/zephyr-docker/actions/workflows/docker-publish.yml/badge.svg)](https://github.com/beriberikix/zephyr-docker/actions/workflows/docker-publish.yml) 7 | 8 | Develop Zephyr applications locally using Docker. No other tools required* besides `docker` & `git`! The container image includes all the tools needed to fetch, build, flash & debug, while your source code can stay on your local machine. 9 | 10 | *_mostly_, depends on OS. 11 | 12 | # Getting container images 13 | 14 | ## Build images locally 15 | 16 | Building images locally ensures you can trust the source of the image, as well as allow you to modify the container image configuration. 17 | 18 | ### Building with Docker CLI 19 | 20 | _To build an image for Arm Cortex-M targets:_ 21 | 22 | ``` 23 | docker build --build-arg ZEPHYR_SDK_TOOLCHAINS="-t arm-zephyr-eabi" --build-arg ZEPHYR_SDK_VERSION=0.16.4 -t zephyr:arm-0.16.4sdk . 24 | ``` 25 | 26 | _To build an image for multiple toolchains:_ 27 | 28 | ``` 29 | docker build --build-arg ZEPHYR_SDK_TOOLCHAINS="-t arm-zephyr-eabi -t x86_64-zephyr-elf" --build-arg ZEPHYR_SDK_VERSION=0.16.4 -t zephyr:arm_x86-0.16.4sdk . 30 | ``` 31 | 32 | > :warning: Experimental: Smaller images with Alpine 33 | 34 | Alpine Linux is a lightweight Linux distro that's commonly used as the basis of Docker containers to reduce their size. In order to build a container image image using Alpine instead of Debian: 35 | 36 | ``` 37 | docker build --build-arg ARCHITECTURE=x86_64 --build-arg ZEPHYR_SDK_VERSION=0.16.0 --build-arg ZEPHYR_VERSION=v3.2.0 --build-arg TOOLCHAIN=arm-zephyr-eabi -t zephyr-arm:alpine-v3.2.0-0.16.0sdk -f Dockerfile.alpine . 38 | ``` 39 | 40 | ### Important build arguments 41 | 42 | * ZEPHYR_SDK_VERSION - SDK version. Must be 0.14.1 or later. Default 0.16.4. 43 | * ZEPHYR_SDK_TOOLCHAINS - target toolchain. Default arm. 44 | 45 | ## Download prebuilt images 46 | 47 | Prebuilt container images can be used instead of having to build locally. Prebuilts are created using Github Actions daily and hosted on the Github Container Registry. 48 | 49 | Each container image supports a single target architecture under the `zephyr` package. See all packages [here](https://github.com/beriberikix/zephyr-docker/pkgs/container/zephyr). 50 | 51 | NOTE: Previously images were tagged like `zephyr-arm` and had a different implementation. The old images are incompatible with the new images but previous versions are kept around for backwards compatibility. 52 | 53 | Install from the commandline: 54 | 55 | ``` 56 | docker pull ghcr.io/beriberikix/zephyr:arm-0.16.4sdk 57 | ``` 58 | 59 | Use as a base image in a Dockerfile: 60 | 61 | ``` 62 | FROM ghcr.io/beriberikix/zephyr:arm-0.16.4sdk 63 | ``` 64 | 65 | # Develop with Docker 66 | 67 | The container image can be used to build any compatible Zephyr application, including in-tree samples or custom application. There are several ways to use a Docker container for development. 68 | 69 | ## Interactive mode 70 | 71 | A container can be used in a like you would use a Virtual Machine. Here is an example following the official Getting Started Guide but with much less setup. 72 | 73 | ``` 74 | docker run -it --name zephyr-gsg ghcr.io/beriberikix/zephyr:arm-0.16.4sdk 75 | west init ~/zephyrproject 76 | cd ~/zephyrproject 77 | west update 78 | west zephyr-export 79 | cd ~/zephyrproject/zephyr 80 | pip install -r scripts/requirements.txt 81 | west build -b mimxrt1060_evkb samples/basic/minimal -p 82 | exit 83 | ``` 84 | 85 | The container will stop after you `exit` and will remain on your machine in the previous state (again, like a VM.) To restart the container where you left off use `docker start.` 86 | 87 | Using the GSG example: 88 | 89 | ``` 90 | docker start -ia zephyr-gsg 91 | ``` 92 | ## Seamless mode 93 | 94 | TODO 95 | 96 | ## GitHub Actions 97 | 98 | TOOD 99 | 100 | # Notes 101 | 102 | 1. Currently only supports local development. CI integration planned for the future. 103 | 2. Supports Zephyr SDK 0.16.0 and later. 104 | 3. Pre-builts currently only target x86_64 hosts. 105 | 106 | # Acknowledgement 107 | 108 | Special thanks to the ZMK maintainers. This implementation was originally based on [zmk-docker](https://github.com/zmkfirmware/zmk-docker) but has since been re-written. 109 | --------------------------------------------------------------------------------