non-zero code will fail the build

This afternoon I was updating the Dockerfile to add the npm audit command and trying to build the image afterward. The interesting behaviour I just know was that the docker will fail the build as the npm audit command returned non-zero code:

found 34 high severity vulnerabilities in 2544 scanned packages
  run `npm audit fix` to fix 34 of them.
The command '/bin/sh -c npm audit' returned a non-zero code: 1

Here is the Dockerfile code snippet:

FROM dev as test
COPY . .
RUN npm audit && npm audit fix

In my case, I could simply ignore the npm audit error code by forcing the RUN to return 0 exit code:

FROM dev as test
COPY . .
RUN npm audit; exit 0 && npm audit fix

Note that in this case it still make a lot of sense while in other script we still want to return the exit code as is.

Leave a comment