Common causes
- A package install failed (apt-get, npm install, pip install) due to a missing dependency or network issue
- A command references a binary or script that doesn't exist in the base image at that point in the build
- A compilation or build step inside the container failed due to missing libraries or code errors
- Shell syntax error in the RUN instruction — missing quotes, wrong escaping, or bad pipe handling
How to fix it
- Add --no-cache to see the full error: docker build --no-cache -t myapp . then read the output above the 'returned a non-zero code' line
- Run the failing command interactively: docker run -it base-image /bin/sh, then run the command manually
- For apt-get failures: ensure you run apt-get update before apt-get install in the same RUN layer
- Chain commands with && so failures stop the layer: RUN apt-get update && apt-get install -y curl
Example
$ docker build .
Step 4/8 : RUN npm install
---> Running in 3f2c1b9a0d7e
npm ERR! missing package.json
The command '/bin/sh -c npm install' returned a non-zero code: 1npm install fails because package.json wasn't copied into the container before this RUN step
Browse more errors
The Developer Hub covers 150+ errors across Git, npm, Node.js, Python, TypeScript, and Docker — with plain-English explanations and fix steps.
