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
Solved: I need to do COPY . . then RUN npm run build.
the main.js file in dist is located on /dist/src/main.js