Home > Net >  Error: Cannot find module '/app/app.js' docker in ubuntu 22.04
Error: Cannot find module '/app/app.js' docker in ubuntu 22.04

Time:01-26

I'm learning Docker as a beginner I have to faced this error When I was run this command on my ubuntu 22.04 terminal. Command bellow:

docker run hello-docker

But unfortunately my terminal says:

node:internal/modules/cjs/loader:1056
  throw err;
  ^

Error: Cannot find module '/app/app.js'
    at Module._resolveFilename (node:internal/modules/cjs/loader:1053:15)
    at Module._load (node:internal/modules/cjs/loader:898:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:84:12)
    at node:internal/main/run_main_module:23:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

Node.js v19.4.0

I need to run my simple js code on docker. Is is file or folder permission issues?

Here is file structure:

project dir: /var/www/hello-docker
project file: app.js, Dockerfile
app.js:
console.log('Hello Docker')
Dockerfile:
FROM node:alpine
COPY . /app
WORKDIR /app
CMD node app.js

Build docker file:

sudo docker build -t hello-docker

Run docker image:

sudo docker run hello-docker

Finally I have got error, Previously I have attached.

Thanks

CodePudding user response:

Your are missed the npm install command on dockerfile

Dcokerfile

FROM node:alpine
WORKDIR /app
COPY . /app
RUN npm install
CMD node app.js
  • Related