This is my Dockerfile:
FROM node:12
WORKDIR /app
COPY . /app
RUN npm install
EXPOSE 3000
CMD ["npm", "start"]
This is the npm script in my package.json
"start": "main.js $npm_config_e $npm_config_t"
when I run the docker image I get this error
sh: 1: main.js: not found
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! [email protected] start: `main.js`
However when I do an 'ls' the main.js is in the working directory (/app) also if I change the Dockerfile to:
CMD ["node", "main.js"]
it works. So why does the npm script not find the main.js file?
main.js
file executable with a#!
interpreter line at the start? In your second invocation when you claim it works, what output do you actually get? (Single quotes in JSON-formatCMD
aren't allowed and are a common cause of an obscure shell error at startup time.)#!
at the start of main.js, is this required for running an npm script in docker? UsingCMD ["node", "main.js"]
(the single quotes were a typo sorry) I get my expected output from Main.js. again without#!
Thanks./main.js
, it either needs to be a native executable or begin with the#!
marker. (Not Docker-specific.)