Skip to content
Latchkey

Dockerfile ONBUILD build trigger failure in CI

Your build runs hidden instructions inherited from the base image. ONBUILD triggers defined in the base fire when you FROM it, and they fail when the context they assume (expected files, structure) is not present.

What this error means

The build prints "# Executing N build triggers" and then fails inside a triggered instruction, for example a COPY failed or a non-zero RUN, even though your own Dockerfile looks fine.

docker build
Step 2/6 : FROM node:onbuild
# Executing 3 build triggers
 ---> Running in a1b2c3d4
COPY failed: file not found in build context or excluded by .dockerignore: stat package.json: file does not exist

Common causes

The base defines ONBUILD instructions

An onbuild style base image carries ONBUILD COPY/ONBUILD RUN triggers that run automatically when you build from it.

The build context does not match the trigger

The triggered instruction expects files (such as package.json) that are not in your build context, so it fails.

How to fix it

Provide what the trigger expects

  1. Read the base image docs to see what its ONBUILD triggers require.
  2. Ensure those files exist in the build context and are not excluded by .dockerignore.
  3. Re-run the build so the triggers find what they need.

Use a base image without ONBUILD

Switch to a plain base and write the COPY/RUN steps explicitly so behavior is visible in your Dockerfile.

Dockerfile
FROM node:20-slim
COPY package.json package-lock.json ./
RUN npm ci

How to prevent it

  • Prefer explicit instructions over inherited ONBUILD triggers.
  • When using an onbuild base, supply exactly the files it expects.
  • Document any ONBUILD behavior your base image relies on.

Frequently asked questions

What causes "ONBUILD trigger fails on FROM"?
An onbuild style base image carries ONBUILD COPY/ONBUILD RUN triggers that run automatically when you build from it.
How do I fix ONBUILD trigger fails on FROM?
Provide what the trigger expects

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card