admin管理员组

文章数量:1336631

Trying to up nodejs with custom scripts, but every time it fails with error (on Linux VM, on Windows it works with the same configuration):

Attaching to app-nodejs
app-nodejs  | npm ERR! Missing script: "start:prod"
app-nodejs  | npm ERR! 
app-nodejs  | npm ERR! To see a list of scripts, run:
app-nodejs  | npm ERR!   npm run

npm run showed (from debug part of Dockerfile):

#13 0.318 Lifecycle scripts included in [email protected]:
#13 0.318   start
#13 0.318     nest start
#13 0.318   test
#13 0.318     jest
#13 0.318 
#13 0.318 available via `npm run-script`:
#13 0.318   build
#13 0.318     nest build
#13 0.318   format
#13 0.318     prettier --write "src/**/*.ts" "test/**/*.ts"
#13 0.318   start:dev
#13 0.318     nest start --watch
#13 0.318   start:debug
#13 0.318     nest start --debug --watch
#13 0.318   start:prod
#13 0.318     node dist/main.js

RUN ls -la dist showed (from debug part of Dockerfile):

...
-rwxr-xr-x 1 root root   11 Nov 19 19:53 main.d.ts
-rwxr-xr-x 1 root root  466 Nov 19 19:53 main.js
-rwxr-xr-x 1 root root  419 Nov 19 19:53 main.js.map
...

Tried to change ENTRYPOINT ["npm", "run", "start:prod"] to ENTRYPOINT ["node", "dist/main.js"], it fails with an error Error: Cannot find module '/usr/src/app/dist/main.js'

Added this to tsconfig.json:

"outDir": "./dist",
"rootDir": "./src",

Checked and changed rights on VM (+x)

Absolutely can't understand what's wrong because I can run the same project on Windows (in docker also) without any problems and errors.

Here's Dockerfile

FROM node:16.20.2

RUN apt-get update && apt-get install -y bash postgresql-client

WORKDIR /usr/src/app
COPY package*.json ./

RUN npm install

COPY . .
RUN chmod -R 755 /usr/src/app && npm run build

RUN chmod -R 755 /usr/src/app/dist && ls -la dist

RUN npm run && node -v && npm -v

EXPOSE 3000

ENTRYPOINT ["npm", "run", "start:prod"]

Container starts with docker-compose up --build --force-recreate, only folders src and test added to volumes, all changes in any config file triggers rebuild, so they don't include to volumes.

!!! One of the comments helped me resolve this problem. I changed ENTRYPOINT ["npm", "run", "start:prod"] to ENTRYPOINT ["npm", "run-script", "start:prod"] and added to Dockerfile:

COPY *.json ./
COPY *.js ./
COPY ./src ./src
COPY ./test ./test

Instead of COPY . ..

本文标签: