"npm install" fails with ECONNREFUSED while building Docker image - docker

I'm trying to build a Docker image that contains NPM and installs some tools, but when I issue the install command, as in:
RUN npm install -g sfdx-cli
The build hangs for a while, and then a lot of errors are thrown. And it is the same error:
npm ERR! fetch failed http://10.252.156.164:4880/#babel%2fcode-frame/-/code-frame-7.0.0.tgz
npm WARN retry will retry, error on last attempt: Error: connect ECONNREFUSED 10.252.156.164:4880
Every other resource I find on the web by searching this error results in an answer/article about using NPM behind a proxy, but that is not the case here. I'm not behind a proxy.
What can I do to make this error stop?
Running RUN echo "${http_proxy}" && echo "${HTTP_PROXY}" in my Dockerfile while building I get the following output:
Step 8/16 : RUN echo "${http_proxy}" && echo "${HTTP_PROXY}"
---> Running in 09bfc89592ae
Removing intermediate container 09bfc89592ae

I am able to build the docker image successfully, here is my Dockerfile,
FROM alpine:3.8
RUN apk add --no-cache nodejs npm
RUN npm install -g sfdx-cli
If you do not want to alpine as a base image then share your Dockerfile.
Or also you can run RUN npm config set registry https://registry.npmjs.com/

Try docker build . --network="host"
(Ref: https://github.com/verdaccio/docker-examples/issues/33)

Related

Docker Build Image issue while running in Azure Pipelines

I am unable to build the Docker images and receiving an authentication error when attempting to build them.
When I copy the SSH key locally and run the build, it is successful. However, when attempting to run it through the pipelines, it fails with the error below. Can someone please help me with this?
I have tried building the Docker image locally and it was successful. Please assist me in building the Docker image through the Azure pipeline.
Dockerfile:
FROM node:16.13.2 as build
WORKDIR /usr/local/app
COPY ./ /usr/local/app/
RUN npm i -g npm#8.1.2
RUN npm cache clear --force
RUN npm install --legacy-peer-deps
RUN npm run build
FROM nginx:latest
COPY --from=build /usr/local/app/dist/angular-app /usr/share/nginx/html
EXPOSE 80

How do I install npm package into Cypress container?

I'm trying to install randomstring package into Cypress container because my tests are using it.
Dockerfile:
FROM cypress/base:17.8.0
RUN npm install randomstring#1.2.2
RUN npm install cypress#7.0.0
COPY . /e2e
RUN npm cypress run
error output I'm getting:
1 error occurred:
* Status: The command '/bin/sh -c npm install randomstring#1.2.2 cypress#7.0.0' returned a non-zero code: 1, Code: 1
I'm aware that Cypress/base image comes with operating system and dependencies required in order to run Cypress but I'm not sure if npm is included.
What is the right way to install packages into Cypress container ?
Any particular reason to use base image?
Have you tried with cypress/included:7.0.0, which already has cypress + browsers installed.
Furthermore it's better to keep all your dependencies (randomstring included) in package.json file where they belong, copy it over and call npm install or npm ci.

Trying to install npm packages in local docker environment + content filtering by internet provider

I want to run local docker.
But I have content filtering by my internet service provider, So it doesn't work correctly.
my docker file :
FROM node:15.14
COPY . .
ENV NODE_ENV=development
RUN npm install --unsafe-perm
RUN npm run build
RUN npm i -g pm2
I tried docker run x and got error :
certificate signed by unknown authority.
Can somebody please tell me how to solve it?
I found a solution.
I added this lines to the dockerFile:
ADD your_provider_certificate_sign_path local_path
RUN cat local_path | sh
ENV NODE_EXTRA_CA_CERTS=/etc/ca-bundle.crt
ENV REQUESTS_CA_BUNDLE=/etc/ca-bundle.crt
ENV SSL_CERT_FILE=/etc/ca-bundle.crt
and it run successfully.

How to install #swc/core-linux-musl on windows, to make it work in docker container?

I'am working on windows. I docernize Next.js with Typescript app.
Here is my dockerfile:
FROM node:alpine
# create directory where our application will be run
RUN mkdir -p /usr/src
WORKDIR /usr/src
# copy our files into directory
COPY . /usr/src
# install dependences
RUN npm install
EXPOSE 3000
ENTRYPOINT ["npm", "run" ,"dev"]
During development I bind host catalogue to container by --mount type=bind,source=d:/apps/library.next.js/,target=/usr/src. When I start container I get error: error - Failed to load SWC binary for linux/x64, see more info here: https://nextjs.org/docs/messages/failed-loading-swc.
That's fine, I understand error and know what to do. To fix this I need to install #swc/cli #swc/core #swc/core-linux-musl, but I can't doing it because npm complain:
ERR! code EBADPLATFORM npm
ERR! notsup Unsupported platform for #swc/core-linux-musl#1.2.42: wanted {"os":"linux","arch":"x64"} (current: {"os":"win32","arch":"x64"})
How to install it on windows, or how to change docker setup to make it work? I must install it locally then it will be linked (by binding !) into container.
My workaround for now is to get into container by docker exec -it <id> /bin/sh then manually type npm install -save-dev #swc/cli #swc/core #swc/core-linux-musl. But doing that every time I recreate container is annoying.
The docs state: The -f or --force will force npm to fetch remote resources even if a local copy exists on disk. And it should be in the docs v6 legacy, the one you posted and v8 version. (See the section after --package-lock-only. It comes with an example npm install sax --force). So, you shouldn't have issues with that every time your container is recreating.

Maximum call stack size exceeded npm install by Docker container

I'm trying to npm install by Docker container:
This is a DockerFile:
# default /var/www/html (mapped to .../code folder with projects)
FROM node
WORKDIR /work
# Additional tools (ng, gulp, bower)
RUN npm install -g #angular/cli bower gulp grunt
CMD while true; do sleep 10000; done
EXPOSE 3002 3003 3004
I run and map it with this command:
docker run -d --name node-cmd -p 3002:3002 -p 3003:3003 -p 3004:3004 -v
/m/dockerlogs/node-cmd/logs:/root/.npm/_logs -v /m/projekty:/work node-cmd
I log in to this container with:
docker exec -it node-cmd bash -c "cd /code; bash"
After I run npm install (https://github.com/gdi2290/angular-starter), I write this from logged in container
But I'm getting this error after installation
npm ERR! Maximum call stack size exceeded
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2018-09-17T17_38_34_855Z-debug.log
root#08e3cd77fb83:/work/angular-starter-master#
I was try to delete node_modules, but this problem is always.
Sometimes, after this error, when I again try npm install, console show me this:
npm ERR! path /work/angular-starter-
master/node_modules/#schematics/update/packa
ge.json.2932816706
npm ERR! code ETXTBSY
npm ERR! errno -26
npm ERR! syscall rename
npm ERR! ETXTBSY: text file is busy, rename '/work/angular-starter-
master/node_m
odules/#schematics/update/package.json.2932816706' -> '/work/angular-
starter-mas
ter/node_modules/#schematics/update/package.json'
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2018-09-17T17_14_43_970Z-debug.log
root#08e3cd77fb83:/work/angular-starter-master#
My npm version is 6.4.1
I have a Windows 8.1 and Docker Toolbox
But when I write npm install on Windows without Docker all is OK.
It might be because of different node versions. Check your node version with node -v and use that for the Dockerfile. Check the supported tags and Dockerfile links here: https://hub.docker.com/_/node
In the Dockerfile, I changed from FROM node:alpine AS node_builder to FROM node:lts-alpine AS node_builder and now it works.
Ok, i solved this problem, I was use npm install with --no-bin-links flag. Thanks for answers :)
For me, this ended up being caused by permission issues (I had previously install node_modules outside of docker). Deleting node_modules and only installing from within docker corrected the problem.

Resources