node-pre-gyp not accessible from fsevents - node.js

I am getting the following error when deploying my container
#15 1.066 npm ERR! node-pre-gyp not accessible from fsevents
#15 1.076
#15 1.076 npm ERR! A complete log of this run can be found in:
#15 1.076 npm ERR! /root/.npm/_logs/2022-01-11T11_40_13_120Z-debug.log
------
executor failed running [/bin/sh -c npm ci]: exit code: 1
following is my dockerfile
WORKDIR /app
COPY package*.json ./
COPY .npmrc .npmrc
RUN npm set progress=false
RUN npm ci
RUN npm audit
COPY . .
RUN npm run build
FROM nginx
RUN mkdir /app
COPY --from=0 /app/dist /app
COPY ./__docker_content_start.sh /start.sh
RUN chmod +x /start.sh
COPY nginx.conf /etc/nginx/nginx.conf
CMD /start.sh
I am unable to find a solution for this. Any help appreciated Thanks

Add node-pre-gyp as a dependency to your package.json
npm i --save node-pre-gyp

Related

unable to run npm install in docker image (getting auth error)?

I have a very simple Dockerfile
FROM node:17.3.1 as build
WORKDIR /app
COPY package*.json .
RUN npm install
COPY . .
RUN npm run build
FROM node:17.3.1
WORKDIR /app
COPY package.json .
RUN npm install --only=production
COPY --from=build /app/dist ./dist
CMD npm run start:prod
When running docker build -t nestjs-hello-world . I am getting the following error. I don't understand why it is needing to login to npm. It is using the default registry. Even tried specifying the default registry as part of the npm install command, just to make sure, but same error..
=> ERROR [build 4/6] RUN npm install 8.3s
------
> [build 4/6] RUN npm install:
#8 8.230 npm notice
#8 8.231 npm notice New minor version of npm available! 8.1.2 -> 8.3.1
#8 8.231 npm notice Changelog: <https://github.com/npm/cli/releases/tag/v8.3.1>
#8 8.232 npm notice Run `npm install -g npm#8.3.1` to update!
#8 8.233 npm notice
#8 8.235 npm ERR! code E401
#8 8.237 npm ERR! Unable to authenticate, your authentication token seems to be invalid.
#8 8.238 npm ERR! To correct this please trying logging in again with:
#8 8.239 npm ERR! npm login
#8 8.251
#8 8.252 npm ERR! A complete log of this run can be found in:
#8 8.252 npm ERR! /root/.npm/_logs/2022-01-20T00_08_48_935Z-debug.log
Any ideas why this is happening for me please?
Thanks
Thanks to Phil I had the same problem and I managed to unblock my problem thanks to your comment
Here is my Dockerfile
FROM node:16
# Create app directory
WORKDIR /usr/src/app
# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm#5+)
# copying packages first helps take advantage of docker layers
COPY package.json .
RUN npm install prettier -g
# If you are building your code for production
RUN npm install
# Bundle app source
COPY . .
RUN npm run build
EXPOSE 4000
CMD [ "node", "dist/server.js" ]

Copy output of npm install to docker container

I dockerized node.js and all works fine
Dockerfile:
FROM node:alpine
WORKDIR '/app'
COPY package.json .
RUN npm install
COPY . .
EXPOSE 9000
CMD ["npm", "run", "dev"]
I'm trying to run npm install outside Dockerfile and to copy content of npm install to docker container
On docker host i ran
npm install --prefix /opt/npm/ -g
Folder /opt/npm/lib/node_modules/ui is created. In that folder there are bunch json files and folder node_modules.Dockerfile is in that foler.Now, in Dockerfile i skipped npm install and just copied content of /opt/npm/lib/node_modules/ui to docker container.
Modified Dockerfile
FROM node:alpine
WORKDIR '/app'
COPY . .
EXPOSE 9000
Built image from Dockerfile sucessfully, but when trying to run container from that image
docker run -p 9000:4200 pm
> ui#0.0.0 dev /app
> ng serve --host 0.0.0.0 --proxy-config src/proxy.conf.json
sh: ng: not found
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! ui#0.0.0 dev: `ng serve --host 0.0.0.0 --proxy-config src/proxy.conf.json`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the ui#0.0.0 dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?
Is it possible to run npm install outside docker container ?
When dockerizing any application you should always compile and install dependencies in the docker container.
Your Docker file start form node:alpine. this means that when you install an npm package that needs compilation outside (your OS) the alpine OS won't be able to use this.
Best practice is to always build your application on the same OS. That's way docker introduce build container.
# Dockerfile
FROM node:12.13-alpine As build
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install --only=production
FROM node:12.13-alpine as production
WORKDIR /usr/src/app
COPY ./ ./ # copy static files
COPY --from=build /usr/src/app/node_modules ./. # Copy node_modules from build container
EXPOSE 3000
CMD ["node", "main.js"]
# .dockerignore
node_modules
Dockerfile
Try to fit this to your environment

Docker container that pulls from private gilab repository

I'm building a Docker container for my Node.js + Vue application.
Since I have a global css library in another repository I have added this line in my package.json file:
"lib-css": "git+ssh://git#git.lib.com:9922/username/lib-css.git#development",
That way when I run npm install I install also my CSS library. The problem is that on my local env it asks for my password and I can insert it, but in the Docker build the process fails with the following error:
Step 7/10 : RUN npm install
---> Running in db10ca83586d
npm WARN deprecated babel-preset-es2015#6.24.1: 🙌 Thanks for using Babel: we recommend using babel-preset-env now: please read babeljs.io/env to update!
npm ERR! Error while executing:
npm ERR! /usr/bin/git ls-remote -h -t ssh://git#git.lib.com:9922/username/lib-css.git
npm ERR!
npm ERR! Host key verification failed.
npm ERR! fatal: Could not read from remote repository.
npm ERR!
npm ERR! Please make sure you have the correct access rights
npm ERR! and the repository exists.
npm ERR!
npm ERR! exited with error code: 128
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2017-12-11T08_49_11_152Z-debug.log
This is my current Dockerfile:
FROM node:carbon
WORKDIR /usr/src/app
RUN mkdir -p /root/.ssh
COPY .secrets /root/.ssh/id_rsa
RUN chmod 700 /root/.ssh && chmod 600 /root/.ssh/*
# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm#5+)
COPY package*.json ./
RUN npm install
# If you are building your code for production
# RUN npm install --only=production
# Bundle app source
COPY . .
EXPOSE 8081
CMD [ "npm", "run dev" ]
~
My .secrets file contains my private key associated to the repository.
How can I make this works?

Docker image creation throwing "no such file or directory, access '/node_modules/sails'" when dockerizing a sails.js app

Below is the Dockerfile
FROM node:latest
RUN npm install -g sails#0.12.13
ADD . / ./
RUN npm install
EXPOSE 80
CMD (sails lift)
Image creation fails with following log:
ending build context to Docker daemon 70.03MB
Step 1/6 : FROM node:latest
---> 60bea5b86079
Step 2/6 : RUN npm install -g sails#0.12.13
---> Using cache
---> 3f3c7fcdb090
Step 3/6 : ADD . / ./
---> Using cache
---> 78700b41cf26
Step 4/6 : RUN (npm install)
---> Running in d49423611a77
npm info it worked if it ends with ok
npm info using npm#5.3.0
npm info using node#v8.4.0
npm info lifecycle ecs-notification#0.0.0~preinstall: ecs-notification#0.0.0
npm WARN checkPermissions Missing write access to /node_modules/sails
npm ERR! path /node_modules/sails
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall access
npm ERR! enoent ENOENT: no such file or directory, access '/node_modules/sails'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2017-09-08T13_00_06_956Z-debug.log
The command '/bin/sh -c (npm install)' returned a non-zero code: 254
Even if I try to create the directory, or change the permission to 777 using:
RUN (mkdir -p /node_modules/sails; chmod 777 /node_modules/sails)
it still fails with the same error:
Sending build context to Docker daemon 70.03MB
Step 1/7 : FROM node:latest
---> 60bea5b86079
Step 2/7 : RUN npm install -g sails#0.12.13
---> Using cache
---> 3f3c7fcdb090
Step 3/7 : RUN (mkdir -p /node_modules/sails; chmod 777 /node_modules/sails)
---> Using cache
---> c7f1784c24c8
Step 4/7 : ADD . / ./
---> Using cache
---> 334017659dde
Step 5/7 : RUN (npm install)
---> Running in 833e3ef6a010
npm info it worked if it ends with ok
npm info using npm#5.3.0
npm info using node#v8.4.0
npm info lifecycle ecs-notification#0.0.0~preinstall: ecs-notification#0.0.0
npm WARN checkPermissions Missing write access to /node_modules/sails
npm ERR! path /node_modules/sails
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall access
npm ERR! enoent ENOENT: no such file or directory, access '/node_modules/sails'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2017-09-08T13_13_55_258Z-debug.log
The command '/bin/sh -c (npm install)' returned a non-zero code: 254
Docker version: 17.06.2-ce-mac27 (19124)
Any pointers around how I can debug this?
Change your Dockerfile to below
FROM node:latest
RUN npm install -g sails#0.12.13
WORKDIR /usr/app
COPY package.json ./
RUN npm install
COPY . ./
EXPOSE 80
CMD sails lift
You should only copy package.json first and the do npm install and then copy code. Also your ADD statement was wrong. There was an extra space
Next make sure you have .dockerignore which ignores the node_modules. Else node_modules will be overwritten by the copy operation

Got errors with ONBUILD options (Docker toolbox in Windows)

I have a problem with my Docker on Windows (through Docker Toolbox). May be someone can help.
My Dockerfile without ONBUILD:
FROM node:5.9.1
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY package.json /usr/src/app/
RUN npm install
COPY . /usr/src/app
CMD [ "npm", "start" ]
EXPOSE 3000
Working ok (docker build -t test . and start it: docker run -it --rm --name testrun test)
But if i change Dockerfile to ONBUILD option:
FROM node:5.9.1
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
ONBUILD COPY package.json /usr/src/app/
ONBUILD RUN npm install
ONBUILD COPY . /usr/src/app
CMD [ "npm", "start" ]
EXPOSE 3000
I get an errors:
npm info it worked if it ends with ok
npm info using npm#3.7.3
npm info using node#v5.9.1
npm ERR! Linux 4.1.19-boot2docker
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "start"
npm ERR! node v5.9.1
npm ERR! npm v3.7.3
npm ERR! path /usr/src/app/package.json
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall open
npm ERR! enoent ENOENT: no such file or directory, open '/usr/src/app/package.js
on'
npm ERR! enoent ENOENT: no such file or directory, open '/usr/src/app/package.js
on'
npm ERR! enoent This is most likely not a problem with npm itself
npm ERR! enoent and is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! Please include the following file with any support request:
npm ERR! /usr/src/app/npm-debug.log
Whats im doing wrong? (im novice in Docker :) ). Maybe I'm wrong use ONBUILD? But like anything not clear there is no.
As mentioned in Dockerfile man page:
The ONBUILD instruction adds to the image a trigger instruction to be executed at a later time, when the image is used as the base for another build.
Since you are not using another image starting with "FROM test", those instruction are never executed, meaning the test image does not include what those commands were supposed to do.
Unless you left out some details in your question, you're not using ONBUILD correctly.
The ONBUILD option is to queue commands to run in a subsequent build. The commands you specified above wouldn't be executed unless you wrapped your image by including it in the FROM reference in another Dockerfile.
Please see the Dockerfile reference on this subject for additional information.

Resources