I want to run a NodeJS script when building the docker image, it works fine locally.
Here is my docker image:
WORKDIR /usr/src/app
# Installing dependencies
COPY package.json *yarn* .npmrc ./
RUN yarn install
# Running Excel to JSON script
# Copy working directory to container
COPY . .
RUN node importExcel.js
# Building app
RUN yarn build
EXPOSE 3000
# Running the app
CMD [ "yarn", "start" ]
I get this error when building the image:
Step 14/17 : RUN node importExcel.js
---> Running in 8d666299a084
node:internal/modules/cjs/loader:936
throw err;
^
Error: Cannot find module '/usr/src/app/importExcel.js'
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
at node:internal/main/run_main_module:17:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
Removing intermediate container 8d666299a084
The command '/bin/sh -c node importExcel.js' returned a non-zero code: 1
I get this error even though the file is located in /usr/src/app/
.
Make sure that you really copied your files. Try RUN ls -la
before you start node command
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.