I cannot install packages nodejs packages on docker? - node.js

I am new on docker. I first build dockerfile after install get only error. This is Dockerfile:
FROM node
WORKDIR '/app'
COPY package*.json .
RUN npm i -g npm#latest
RUN npm install
COPY . .
CMD ["npm", "run", "start"]
When run docker build . command I get this error:
=> ERROR [5/6] RUN npm install 150.9s
------
> [5/6] RUN npm install:
#9 43.89 npm WARN deprecated w3c-hr-time#1.0.2: Use your platform's native performance.now() and performance.timeOrigin.
#9 73.65 npm WARN deprecated svgo#1.3.2: This SVGO version is no longer supported. Upgrade to v2.x.x.
#9 88.65 npm WARN deprecated stable#0.1.8: Modern JS already guarantees Array#sort() is a stable sort, so this library is deprecated. See the compatibility table on MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#browser_compatibility
#9 149.2 npm ERR! code ERR_SOCKET_TIMEOUT
#9 149.2 npm ERR! network Socket timeout
#9 149.2 npm ERR! network This is a problem related to network connectivity.
#9 149.2 npm ERR! network In most cases you are behind a proxy or have bad network settings.
#9 149.2 npm ERR! network
#9 149.2 npm ERR! network If you are behind a proxy, please make sure that the
#9 149.2 npm ERR! network 'proxy' config is set properly. See: 'npm help config'
#9 149.3
#9 149.3 npm ERR! A complete log of this run can be found in:
#9 149.3 npm ERR! /root/.npm/_logs/2023-02-17T12_09_49_294Z-debug-0.log
------
executor failed running [/bin/sh -c npm install]: exit code: 1

This is a Dockerfile that works for me
FROM node:18-bullseye
WORKDIR /node-app
COPY package-lock.json package.json ./
RUN npm ci
COPY . .
Your issue is to remove the quote from the WORKDIR '/app' when copying the package-lock.json and package.json they should be COPYed to ./
The 3rd line RUN npm ci, is used to install packages that are in your package-lock.json file so you keep the same libraries as a BEST PRACTICE, npm install it may fetch some updates to some packages that you have, so as I mentioned, it's a best practice to use npm ci instead of npm install

Related

Railway app not able to install when deploying NestJS application

I am trying to deploy a NestJS application on Railway.
I am using NPM as my package manager.
I have explicitly defined a run command and a build command in the project settings.
Whenever I try to deploy the project, I get the following error.
#13 3.042 npm WARN config production Use `--omit=dev` instead.
#13 3.134 npm ERR! Missing script: "install"
#13 3.134 npm ERR!
#13 3.134 npm ERR! Did you mean this?
#13 3.134 npm ERR! npm uninstall # Remove a package
#13 3.135 npm ERR!
#13 3.135 npm ERR! To see a list of scripts, run:
#13 3.135 npm ERR! npm run
#13 3.137
#13 3.137 npm ERR! A complete log of this run can be found in:
#13 3.137 npm ERR! /root/.npm/_logs/2023-01-14T18_01_46_797Z-debug-0.log
Has anybody experienced this before, where it can't recognize the install command?
I have tried with and without the custom build command, but every time it fails when running the npm run install step in the docker container.
I think the command that should run to install is npm install instead of npm run install. Have you tried checking the package.json file and tried adding "install": "npm install" inside scripts

Docker and NPM private registry

i use jetbrains space-on-permises on my pc. When i try to build a node docker image with a npm registry set in the npm registry i've a error:
this is my docker file:
# Builder stage
FROM node:18 as builder
WORKDIR /usr/src/app
COPY package.json ./
COPY snkrs-url.json ./
COPY .npmrc ./
COPY . .
RUN npm config delete proxy
RUN npm config set #sneakers-monitor:registry http://packages:8390/npm/p/sneakers-monitor/npm/
RUN npm config set //packages:8390/npm/p/sneakers-monitor/npm/:_authToken=eyJhbGciOiJSUzUxMiJ9.eyJzdWIiOiIxbjdENmoxc1Y0ZHQiLCJhdWQiOiJjaXJjbGV0LXdlYi11aSIsIm9yZ0RvbWFpbiI6ImpldGJyYWlucyIsIm5hbWUiOiJhZG1pbiIsImlzcyI6Imh0dHA6XC9cL2xvY2FsaG9zdDo4MDg0IiwicGVybV90b2tlbiI6IjJuWHFuRDRYRTVCTiIsInByaW5jaXBhbF90eXBlIjoiVVNFUiIsImlhdCI6MTY3MDY3Njk1Mn0.g7sOBo7r7SvNuWq7VvKttdusdMf5Vad2Als24xBuGFDBId1oGa6XG61Y6X98mE_lifvtMxydD5DFspe49lH2TyS2hhNUI2vYxMno9jcA3oWGNjXMuK8cpAEterD70aNl_yCT-bS2hTh0jeVUKtLewGvoiXIPOvrCTMnyYpHA_qmixi1Qtw49O5rnB9SzTx6Go_iHUJB1p4ZFhEvY_mH8AVFSTo00YRE-RQEQ0j3p54me9amlC5xUTRg6c3bI5J9ElqVPgKn2arODsITKtYkD3vS6K3MRUtCnrr2eKxw3LtDYH1GfXq-hCw5TlYxWiBB_z21U7tnpOCKM8GkxrH-E3hdlYwt4ychoFveDclQKCC8PsMVOWOI9oaMqVttWMz9HkgvAEB3y--pV54s_pHm6xrH_CrYL2oEZ6rELjyJDaZYB-EPpLOrRRIXOYlitYUpe8nKcz13I7HEChpT0huXiP6IWqdotvtSdnR89irqoDILH7RZbGGjkFYB6Yz04zPwzn91-CBONuTMRLm39iv880l2tU6-7BlM2Jivyx0I_IKJCqJjymE0zfXJqB9I1F1S4T2GHBALHbTXtXa9dgC-unwJN3L_4TEPxaozzzcH8ikld8GOcd3bXJX1d-iD4GjqX9ek8cidwqmRzR3ZobAVKnb7_NC0vrXxG14BTqrvJNBg
RUN npm install
RUN npm run build
RUN npm prune --production
RUN wget https://gobinaries.com/tj/node-prune --output-document - | /bin/sh && node-prune
# Runner stage
FROM node:18-alpine as runner
WORKDIR /usr/src/app
COPY --from=builder /usr/src/app/snkrs-url.json ./
COPY --from=builder /usr/src/app/dist ./dist
COPY --from=builder /usr/src/app/node_modules ./node_modules
EXPOSE 5000
CMD [ "node", "dist/index.js" ]
And this is the error:
#18 188.0 npm ERR! code ENOTFOUND
#18 188.0 npm ERR! syscall getaddrinfo
#18 188.0 npm ERR! errno ENOTFOUND
#18 188.0 npm ERR! network request to http://packages:8390/npm/p/sneakers-monitor/npm/#sneakers-monitor%2fdiscord-bot failed, reason: getaddrinfo ENOTFOUND packages
#18 188.0 npm ERR! network This is a problem related to network connectivity.
#18 188.0 npm ERR! network In most cases you are behind a proxy or have bad network settings.
#18 188.0 npm ERR! network
#18 188.0 npm ERR! network If you are behind a proxy, please make sure that the
#18 188.0 npm ERR! network 'proxy' config is set properly. See: 'npm help config'
#18 188.0
Can anyone help me?

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" ]

Dockerfile with angular and nginx fails at the build phase

I'm trying to build a docker image for my project with angular and nginx, but I get the following errors at the build phase when trying to mount the image (install seems to work fine):
#11 103.1 Error: src/app/models/index.ts:5:28 - error TS2307: Cannot find module './inputField' or its corresponding type declarations.
#11 103.1
#11 103.1 5 export { InputField } from './inputField';
#11 103.1 ~~~~~~~~~~~~~~
#11 103.1
#11 103.1
#11 103.1
#11 103.1 npm ERR! code ELIFECYCLE
#11 103.1 npm ERR! errno 1
#11 103.2 npm ERR! myproject#11.0.0 build: `ng build --build-optimizer --output-hashing=none`
#11 103.2 npm ERR! Exit status 1
#11 103.2 npm ERR!
#11 103.2 npm ERR! Failed at the myproject#11.0.0 build script.
#11 103.2 npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
#11 103.2
#11 103.2 npm ERR! A complete log of this run can be found in:
#11 103.2 npm ERR! /root/.npm/_logs/2021-07-17T10_12_55_066Z-debug.log
------
executor failed running [/bin/sh -c npm run build]: exit code: 1
My dockerfile:
# Angular image
FROM node:latest as build
WORKDIR /app
COPY . .
RUN npm install
RUN npm run build
# Nginx image
FROM nginx:latest
COPY --from=build /dist/angular/ /usr/share/nginx/html/
EXPOSE 80
I've done npm audit fix to solve a couple issues and I've deleted node_modules folder, cache and package-lock.json, and installed again, but none of that seems to help.
Thanks in advance.
According to the original issue:
error TS2307: Cannot find module './inputField'
Renaming a file from InputField.ts to inputField.ts solved the problem with the build inside a container.
Looking inside Build Container:
Running only a build container was an excellent comment from #David Maze
something like this:
$ docker run --rm -it <name_of_the_container> /bin/bash
this way you can issue a npm run build command and see what is happening inside.
What I also recommend is to have a clean ng new ngApp as a reference.
If that app can be built then something else is the problem and not the Dockerfile.
Sample:
# Angular build image
FROM node:latest as builder
WORKDIR /app
COPY . .
RUN npm install
RUN npm run build
# Nginx image
FROM nginx:latest
COPY --from=builder /app/dist/ngApp /usr/share/nginx/html/
EXPOSE 80
Try running ng build command locally before building the docker image. It will show the errors. Currently it can't access the InputField.
export { InputField } from './inputField';

Latest version of npm required to install

I'm a newbie in coding so please take it easy on me.
I have project on github, made by softwarehouse - its MVP of an app made with Django Rest framework, React app, Docker.
Now I want to run it on my mac, and there is an issue.
When i run docker-compose.yml i start with docker-compose up, it is instaling all packages untill it goes to the step where it tries to instal npm, and i get an error:
npm notice
npm notice New patch version of npm available! 7.4.0 -> 7.4.3
npm notice Changelog: <https://github.com/npm/cli/releases/tag/v7.4.3>
npm notice Run `npm install -g npm#7.4.3` to update!
npm notice
ERROR: Service 'pet-frontend' failed to build : The command '/bin/sh -c npm install --silent' returned a non-zero code: 1
Failed to deploy 'Compose: docker-compose.yml': `docker-compose` process finished with exit code 1
I don't know why i cannot instal latest version? I have newest node.js where npm is 7.4.0.
How i can force install of 7.4.0 or how to install 7.4.0? so deployment could go further?
__ more info __
frontend dockerfile looks like this:
FROM node:latest
WORKDIR /app
ENV PATH /app/node_modules/.bin:$PATH
COPY package.json ./
RUN npm install --silent
RUN npm install react-scripts#3.4.1 -g --silent
COPY . ./
CMD ["npm", "start"]
when i add there 'RUN npm install -g npm#7.4.3' - still get the same error
When i run npm without --silent i get this error:
npm notice
npm notice New patch version of npm available! 7.4.0 -> 7.4.3
npm notice Changelog: <https://github.com/npm/cli/releases/tag/v7.4.3>
npm notice Run `npm install -g npm#7.4.3` to update!
npm notice
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! Found: prop-types#15.6.0
npm ERR! node_modules/prop-types
npm ERR! peer prop-types#"<=15.6.0" from check-prop-types#1.1.2
npm ERR! node_modules/check-prop-types
npm ERR! dev check-prop-types#"^1.1.2" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! react-leaflet-search#"^2.0.1" from the root project
npm ERR!
npm ERR! Conflicting peer dependency: prop-types#15.7.2
npm ERR! node_modules/prop-types
npm ERR! peer prop-types#"^15.7.2" from react-leaflet-search#2.0.1
npm ERR! node_modules/react-leaflet-search
npm ERR! react-leaflet-search#"^2.0.1" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
npm ERR! See /root/.npm/eresolve-report.txt for a full report.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2021-01-26T10_49_01_333Z-debug.log
ERROR: Service 'petsy-frontend' failed to build : The command '/bin/sh -c npm install' returned a non-zero code: 1
Failed to deploy 'Compose: docker-compose.yml': `docker-compose` process finished with exit code 1
I added the following line before npm install and it worked for me. It picks the latest npm version and install in your directory
RUN npm install -g npm#7.19.1
npm install npm#{latest version}
You can use this, it worked for me just now

Resources