dockerfilelint icon indicating copy to clipboard operation
dockerfilelint copied to clipboard

TypeError: Cannot read property 'reduce' of null

Open AmauryOrtega opened this issue 5 years ago • 7 comments

When using this Dockerfile with the latest dockerfilelint docker image, an internal error shows up. I checked using /bin/sh to make sure the Dockerfile is accessible, I tried moving the Dockerfile to the working directory of /dockerfilelint/ and using the binary inside /dockerfilelint/bin/ but I got the same error message.

Dockerfile

FROM node:12-alpine as dependencies

# Source directory
WORKDIR /usr/src/app/
RUN chown -R node:node .
USER node

# Dependencies
COPY --chown=node:node package*.json ./
RUN npm ci

# Source code and build configuration
COPY --chown=node:node angular.json tsconfig*.json ./
COPY --chown=node:node ngsw-config.json .
COPY --chown=node:node src/ src/

# Compilation
FROM dependencies as build
RUN npx ng build --prod

FROM nginx:stable-alpine
# hadolint ignore=DL3018
RUN apk --no-cache add curl \
   && rm -rf /var/cache/apk/*
HEALTHCHECK CMD curl -f http://localhost/ || exit 1

COPY --chown=nginx:nginx --from=build /usr/src/app/dist/bouwmapp-frontend/ /usr/share/nginx/app/
COPY --chown=nginx:nginx nginx/app.conf /etc/nginx/conf.d/default.conf
EXPOSE 80

Command

docker run --rm -v "$PWD"/Dockerfile:/Dockerfile:ro replicated/dockerfilelint:latest /Dockerfile

Output

/dockerfilelint/lib/checks.js:194
      if (!options.reduce((valid, item) => valid &&
                   ^
TypeError: Cannot read property 'reduce' of null
    at Object.is_valid_healthcheck (/dockerfilelint/lib/checks.js:194:20)
    at runLine (/dockerfilelint/lib/index.js:287:16)
    at Object.module.exports.run (/dockerfilelint/lib/index.js:63:18)
    at processContent (/dockerfilelint/bin/dockerfilelint:92:50)
    at argv._.forEach (/dockerfilelint/bin/dockerfilelint:86:3)
    at Array.forEach (<anonymous>)
    at Object.<anonymous> (/dockerfilelint/bin/dockerfilelint:65:8)
    at Module._compile (internal/modules/cjs/loader.js:702:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:713:10)
    at Module.load (internal/modules/cjs/loader.js:612:32)

AmauryOrtega avatar Aug 26 '20 14:08 AmauryOrtega

I think I am getting the same error, have you tried deleting healthcheck and see if error stops

a16bitsysop avatar Oct 12 '20 21:10 a16bitsysop

@a16bitsysop To give more details, when I originally created this issue, the latest docker image I was using had this image ID ea3ff6887d47.

Using the same image ID and the same Dockerfile without the healthcheck produces this output:

File:   /Dockerfile
Issues: None found 👍

I see that there is a new latest docker image with image ID 24b7b3aae3ac. I've tried both scenarios (with and without healthcheck) but the behavior is the same when the healthcheck is there but the call stack is just slightly different:

/dockerfilelint/lib/checks.js:194
      if (!options.reduce((valid, item) => valid &&
                   ^

TypeError: Cannot read property 'reduce' of null
    at Object.is_valid_healthcheck (/dockerfilelint/lib/checks.js:194:20)
    at runLine (/dockerfilelint/lib/index.js:287:16)
    at Object.module.exports.run (/dockerfilelint/lib/index.js:63:18)
    at processContent (/dockerfilelint/bin/dockerfilelint:92:50)
    at /dockerfilelint/bin/dockerfilelint:86:3
    at Array.forEach (<anonymous>)
    at Object.<anonymous> (/dockerfilelint/bin/dockerfilelint:65:8)
    at Module._compile (internal/modules/cjs/loader.js:1137:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
    at Module.load (internal/modules/cjs/loader.js:985:32)

I'm willing to continue testing new versions so let me know if I can assist in anyway

AmauryOrtega avatar Oct 13 '20 12:10 AmauryOrtega

@AmauryOrtega I am not a developer, I am a user as well. I am trying to find out what is causing it also.

a16bitsysop avatar Oct 13 '20 15:10 a16bitsysop

@AmauryOrtega if you add an option like: HEALTHCHECK --start-period=60s CMD curl -f http://localhost/ || exit 1 It should work, it has to have an option before the command and has to end in || exit 1

a16bitsysop avatar Oct 14 '20 18:10 a16bitsysop

I made a simple fix to this null pointer...

lvjp avatar Jul 29 '21 08:07 lvjp

Thanks @lvjp :tada:

@marccampbell Is the fix acceptable?

AmauryOrtega avatar Jul 30 '21 14:07 AmauryOrtega

I am having the same issue... https://github.com/replicatedhq/dockerfilelint/pull/184 looks good to me as a fix...

szaimen avatar Jun 03 '23 17:06 szaimen