You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

GitHub Actions构建ESP-IDF项目遇docker: command not found错误求助

ESP-IDF GitHub Actions构建失败问题排查与解决

问题描述

首次搭建GitHub Actions CI构建ESP-IDF代码时遇到构建失败,Workflow配置如下:

name: Build

on: [push, pull_request, workflow_dispatch]

jobs:
  build-esp-idf-component:
    name: Build with ESP-IDF ${{ matrix.idf_ver }} for ${{ matrix.idf_target }}
    runs-on: ubuntu-latest
    strategy:
      matrix:
        # The version names here correspond to the versions of espressif/idf Docker image.
        # See https://hub.docker.com/r/espressif/idf/tags and
        # https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/tools/idf-docker-image.html
        # for details.
        idf_ver: ["v4.4.4", "release-v4.4"]
        idf_target: ["esp32"]
    container: espressif/idf:${{ matrix.idf_ver }}
    steps:
      - name: Checkout
        uses: actions/checkout@v3
        with:
          submodules: 'recursive'
      - name: esp-idf build
        uses: espressif/esp-idf-ci-action@v1
        with:
            esp_idf_version: ${{ matrix.idf_ver }}
            target: ${{ matrix.idf_target }}
            path: 'main'

日志输出报错:

Run espressif/esp-idf-ci-action@v1
  with:
    esp_idf_version: v4.4.4
    target: esp32
    path: main
    command: idf.py build
Run export IDF_TARGET=$(echo "esp32" | tr '[:upper:]' '[:lower:]' | tr -d '_-')
  export IDF_TARGET=$(echo "esp32" | tr '[:upper:]' '[:lower:]' | tr -d '_-')
  docker run -t -e IDF_TARGET="${IDF_TARGET}" -v "${GITHUB_WORKSPACE}:/app/NightSkySK/mSpaceLock-device" \
  -w "/app/NightSkySK/mSpaceLock-device/main" espressif/idf:v4.4.4 \
  /bin/bash -c 'git config --global --add safe.directory "*" && idf.py build'
  shell: bash --noprofile --norc -e -o pipefail {0}
/__w/_temp/43fd574a-8b69-4abc-8986-5b3b2e88aca5.sh: line 2: docker: command not found
Error: Process completed with exit code 127.

问题原因

你同时使用了两种容器化构建方式:

  • 给job配置了container: espressif/idf:${{ matrix.idf_ver }},让整个job运行在ESP-IDF的Docker容器内
  • 又调用了espressif/esp-idf-ci-action@v1,这个action本身会尝试启动新的Docker容器来执行构建

但容器环境内部默认没有安装Docker CLI,执行docker run时就会触发docker: command not found错误。

解决方案

两种修正方式二选一即可:

方式1:移除job级别的container配置,让action自行管理容器

保留espressif/esp-idf-ci-action,去掉job的container字段,action会在GitHub Runner的Ubuntu环境中启动Docker容器执行构建:

name: Build

on: [push, pull_request, workflow_dispatch]

jobs:
  build-esp-idf-component:
    name: Build with ESP-IDF ${{ matrix.idf_ver }} for ${{ matrix.idf_target }}
    runs-on: ubuntu-latest
    strategy:
      matrix:
        idf_ver: ["v4.4.4", "release-v4.4"]
        idf_target: ["esp32"]
    # 移除此处的container配置
    steps:
      - name: Checkout
        uses: actions/checkout@v3
        with:
          submodules: 'recursive'
      - name: esp-idf build
        uses: espressif/esp-idf-ci-action@v1
        with:
            esp_idf_version: ${{ matrix.idf_ver }}
            target: ${{ matrix.idf_target }}
            path: 'main'

方式2:直接在job容器内执行构建命令

如果想保留job的container配置,就不需要使用espressif/esp-idf-ci-action,直接在容器内运行构建命令:

name: Build

on: [push, pull_request, workflow_dispatch]

jobs:
  build-esp-idf-component:
    name: Build with ESP-IDF ${{ matrix.idf_ver }} for ${{ matrix.idf_target }}
    runs-on: ubuntu-latest
    strategy:
      matrix:
        idf_ver: ["v4.4.4", "release-v4.4"]
        idf_target: ["esp32"]
    container: espressif/idf:${{ matrix.idf_ver }}
    steps:
      - name: Checkout
        uses: actions/checkout@v3
        with:
          submodules: 'recursive'
      - name: esp-idf build
        working-directory: main
        run: |
          git config --global --add safe.directory "*"
          idf.py build

内容的提问来源于stack exchange,提问作者Szymon Klause

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.20 05:13:24