skip to Main Content

Here is the Dockerfile that I am using to build my nestjs project:

FROM node:14 AS builder
WORKDIR /app
COPY package*.json ./
COPY prisma ./prisma/
COPY protos ./protos/
COPY tsconfig.build.json ./
COPY tsconfig.json ./
RUN npm install
RUN npm run build
COPY . .

FROM node:14-alpine
COPY --from=builder /app/node_modules ./node_modules/
COPY --from=builder /app/package*.json ./
COPY --from=builder /app/dist ./dist/
COPY --from=builder /app/protos ./protos/
COPY --from=builder /app/tsconfig.build.json ./
COPY --from=builder /app/tsconfig.json ./
COPY --from=builder /app/prisma ./prisma/
EXPOSE 5273
CMD ["npm", "run", "start:prod"]

.dockerignore:

.vscode/
node_modules/
npm-debug.log
dist/
graphql/
test/

The container can not work, and I get the :

Cannot find module '/dist/main'

Am I missing something here?

2

Answers


  1. Chosen as BEST ANSWER

    Solved: I need to do COPY . . then RUN npm run build.

    COPY . .    
    RUN npm run build
    

  2. the main.js file in dist is located on /dist/src/main.js

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search