DEV Community

Discussion on: How to Dockerize your NestJS App for production

Collapse
 
hehehai profile image
hehehai

I don't know why this is? , I followed the instructions on the tutorial, but I tried it, and it still didn't solve it!

Step 11/11 : CMD ["npm", "run", "start:prod"]
 ---> Running in e5f55126e787
Removing intermediate container e5f55126e787
 ---> 6a07a1a8b24a
Successfully built 6a07a1a8b24a
Successfully tagged bd-url-query_nest:latest
Creating bd-url-query ... done
Attaching to bd-url-query
bd-url-query |
bd-url-query | > bd-link@0.0.1 start:prod /app
bd-url-query | > node dist/main.js
bd-url-query |
bd-url-query | internal/modules/cjs/loader.js:1032
bd-url-query |   throw err;
bd-url-query |   ^
bd-url-query |
bd-url-query | Error: Cannot find module '/app/dist/main.js'
bd-url-query |     at Function.Module._resolveFilename (internal/modules/cjs/loader.js:1029:15)
bd-url-query |     at Function.Module._load (internal/modules/cjs/loader.js:898:27)
bd-url-query |     at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
bd-url-query |     at internal/main/run_main_module.js:17:47 {
bd-url-query |   code: 'MODULE_NOT_FOUND',
bd-url-query |   requireStack: []
bd-url-query | }
bd-url-query | npm ERR! code ELIFECYCLE
bd-url-query | npm ERR! errno 1
bd-url-query | npm ERR! bd-link@0.0.1 start:prod: `node dist/main.js`
bd-url-query | npm ERR! Exit status 1
bd-url-query | npm ERR!
bd-url-query | npm ERR! Failed at the bd-link@0.0.1 start:prod script.
bd-url-query | npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
bd-url-query | npm WARN Local package.json exists, but node_modules missing, did you mean to install?
bd-url-query |
bd-url-query | npm ERR! A complete log of this run can be found in:
bd-url-query | npm ERR!     /root/.npm/_logs/2020-06-03T14_10_18_871Z-debug.log
bd-url-query exited with code 1
Enter fullscreen mode Exit fullscreen mode
Collapse
 
abbasogaji profile image
Abbas Ogaji • Edited

You might be missing some build dependencies using the alpine version, you can use this instead;

FROM node:10
WORKDIR /app
COPY ./package.json ./
RUN npm install
COPY . .
RUN npm run build
# EXPOSE 3000
CMD ["npm", "run", "start:prod"]

Collapse
 
hehehai profile image
hehehai

Sorry, I did not post the complete configuration. I tried it and found that it was a problem with WORKDIR. It was normal when I ran it for the first time. This problem occurred the second time docker-compose up. is normal. I am trying to find out why.

FROM node:latest

WORKDIR /app/bd-url-query

COPY package*.json .
COPY yarn.lock .

RUN yarn

COPY . .
RUN yarn prebuild && yarn build

CMD [ "node", "dist/main.js"]
Thread Thread
 
abbasogaji profile image
Abbas Ogaji • Edited

" Error: Cannot find module '/app/dist/main.js" it was looking main.js at "/app/dist/main.js" instead of "/app/bd-url-query/dist/main.js"

Just take a look at what you have in your directory, add the ls command i.e "RUN ls -l" before "CMD....." line in your Dockerfile and inspect the files you have there