skip to Main Content

I own an Asustor and I want to dockerise my node js app to be able to run any time.
I followed official tutorial from nodejs but it’s not working as intended on my nas, while on my computer everything is fine.

Here is my Dockerfile :

FROM node:latest
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 8080
CMD ["node", "app.js"]

And here is the error I’m getting on the nas :

Sending build context to Docker daemon  45.57kB
Step 1/7 : FROM node:latest
 ---> b254e440661a
Step 2/7 : WORKDIR /app
 ---> Running in 4ddb713a2c92
Removing intermediate container 4ddb713a2c92
 ---> 7956afe6d600
Step 3/7 : COPY package*.json ./
 ---> 9a814bfae80d
Step 4/7 : RUN npm install
 ---> Running in 477d3abd6312
node:internal/fs/utils:347
    throw err;
    ^

Error: ENOENT: no such file or directory, open '/usr/local/lib/cli.js'
    at Object.openSync (node:fs:591:3)
    at Object.readFileSync (node:fs:459:35)
    at Module._extensions..js (node:internal/modules/cjs/loader:1222:18)
    at Module.load (node:internal/modules/cjs/loader:1068:32)
    at Module._load (node:internal/modules/cjs/loader:909:12)
    at Module.require (node:internal/modules/cjs/loader:1092:19)
    at require (node:internal/modules/cjs/helpers:103:18)
    at Object.<anonymous> (/usr/local/bin/npm:2:1)
    at Module._compile (node:internal/modules/cjs/loader:1205:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1259:10) {
  errno: -2,
  syscall: 'open',
  code: 'ENOENT',
  path: '/usr/local/lib/cli.js'
}

Node.js v19.1.0
The command '/bin/sh -c npm install' returned a non-zero code: 1

2

Answers


  1. Chosen as BEST ANSWER

    I tried a lot of things to get npm working, but none of them worked. So I decided to move to using an alpine linux image and installing node and npm inside it and it worked well on my nas. Thank you for your help and here is my Dockerfile working if you need it :

    FROM alpine:3.17
    RUN apk add --update nodejs npm
    RUN addgroup -S node && adduser -S node -G node
    USER node
    RUN mkdir /home/node/code
    WORKDIR /home/node/code
    COPY --chown=node:node package*.json ./
    RUN npm ci
    COPY --chown=node:node . .
    EXPOSE 9090
    CMD ["node", "app.js"]
    

  2. From the official guide you’ve sent, you can clearly see in the following link, I highlighted the version they used in the main guide and in your Dockerfile your using FROM node:latest meanwhile they are using node:10 can you please edit your Dockerfile and change the latest to 10 in order to fix node version to the

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