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.
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 existCommon 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
- Read the base image docs to see what its ONBUILD triggers require.
- Ensure those files exist in the build context and are not excluded by
.dockerignore. - 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.
FROM node:20-slim
COPY package.json package-lock.json ./
RUN npm ciHow 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.