npm install not able to establish connection inside docker container - docker

I am running docker on ubuntu 16.04. While trying to make my nodejs app inside docker container accessible by https, I made a few changes to port mapping like so:-
docker run -p 127.0.0.1:443:8443/tcp bookshelf-server:0.1 bash
docker run -p 127.0.0.1:80:8443/tcp bookshelf-server:0.1 bash
because I was trying to map port 8443 as I was listening to it for https
This did not work, but it broke my npm install inside docker container. Or maybe something else might have broken it as I was not testing it while trying experiments.
Nevertheless, now when npm run install runs from the docker container, it gives the following error :-
Step 5/13 : RUN npm install
---> Running in 7c78745fb509
npm ERR! code ECONNREFUSED
npm ERR! errno ECONNREFUSED
npm ERR! FetchError: request to https://registry.npmjs.org/body-parser failed, reason: connect ECONNREFUSED 104.16.22.35:443
npm ERR! at ClientRequest.req.on.err (/usr/local/lib/node_modules/npm/node_modules/pacote/node_modules/make-fetch-happen/node_modules/node-fetch-npm/src/index.js:68:14)
I reckon I might have messed up some port connections or something, can anyone give me a direction of how to debug the issue.
Thanks

Related

Input/Output Error on Create-React-App in Docker

I'm trying to dockerize my create-react-app development environment and preserving hot reloads. According to most guides (and this guy), the most direct way is docker run -p 3000:3000 -v "$(pwd):/var/www" -w "/var/www" node npm start in the project folder.
However, I'm getting this error instead:
$ docker run -p 3000:3000 -v "$(pwd):/var/www" -w "/var/www" node npm start
> my-app#0.1.0 start /var/www
> react-scripts start
sh: 1: react-scripts: Input/output error
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! my-app#0.1.0 start: `react-scripts start`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the my-app#0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2020-04-02T06_55_22_257Z-debug.log
I'm running on Windows. I believe mounting the volume might have some permission issues leading to the input/output error, but testing various settings didn't work out. I'm honestly stumped. All I want is to run my app in Docker with hot reload for development.
As it turns out, setting up create-react-app in docker takes a little more work.
The primary issue is that mounted volumes are not available in the build step, so when node npm start runs the mounted project files technically don't exist yet.
As such, you need to copy over and install the project first to let it run the first time before the volume mounts. Hot reloading works normally afterwards.
Here's my final working setup:
docker-compose.yml:
create-react-app:
build:
context: create-react-app
ports:
- 3000:3000
environment:
- NODE_PATH=/node_modules
- CHOKIDAR_USEPOLLING=true
volumes:
- ./create-react-app:/create-react-app
Dockerfile:
FROM node:alpine
# Extend PATH
ENV PATH=$PATH:/node_modules/.bin
# Set working directory
WORKDIR /client
# Copy project files for build
ADD . .
# Install dependencies
RUN npm install
# Run create-react-app server
CMD ["npm", "run", "start"]

"npm install" fails with ECONNREFUSED while building Docker image

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)

Dockerised Jenkins Hangs NPM Install

I've a frustrating issue when "npm install" is executed inside a Jenkins Groovy pipeline using the NodeJS plugin, the process hangs with the following error -
npm install --ddd ng-cli
npm info it worked if it ends with ok
npm verb cli [ '/var/jenkins_home/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/nodejs893-v2/bin/node',
npm verb cli '/var/jenkins_home/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/nodejs893-v2/bin/npm',
npm verb cli 'install',
npm verb cli '--ddd',
npm verb cli 'ng-cli' ]
npm info using npm#5.5.1
npm info using node#v8.9.3
npm verb npm-session e522ad0a36f1c038
npm sill install loadCurrentTree
npm sill install readLocalPackageData
npm http fetch GET 503 https://registry.npmjs.org/ng-cli 70252ms attempt #3
npm sill fetchPackageMetaData error for ng-cli#latest 503 Service Unavailable: ng-cli#latest
npm verb stack Error: 503 Service Unavailable: ng-cli#latest
When the command is executed directly on the EC2, the package installs without issue as the Jenkins user.
Also when the command is executed inside the Jenkins Docker, the package installs without issue as the Jenkins user using the same Node installation.
The Docker instance is not limited by CPU or RAM.
The setup is Jenkins v2.138.1 running inside a Docker container, which in turn is hosted on an EC2 v2018.03. Jenkins home is mounted as an EFS volume. The JVM is running on Java v1.8.0_181. NPM is v5.1.1.
Any pointers would be much appreciated.
Reply to first suggestion
Yes there is direct internet connectivity, without any proxy. If a single package is installed such as
npm install ng-cli
The npm install works without issue.
The issue consisted of two parts -
First off - the EFS mount point directory (/var/jenkins_home) required permissions of 777, it doesn't need to be a recursive permission.
The new EFS disk had content migrated from the old Jenkins EFS and this was also contributing to this issue. The fix was to not transfer any content from the old EFS to the new EFS via the backup.tar.gz feature. The new Jenkins is working as expected with npm install.
Dockerfile pulled from - https://hub.docker.com/r/jenkins/jenkins/

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.

Docker Container works locally but fails on server

I'm fairly new to docker and I'm kind of experimenting with Angular CLI app. I managed to run it locally through my docker container. It works great, but when I try running it from my server it fails.
Server is hosted on DigitalOcean:
512 MB Memory / 20 GB Disk / FRA1 - Ubuntu Docker 17.03.0-ce on 14.04
I used dockerhub to transfer my container to the server.
When logging the container it gives me this:
** NG Live Development Server is running on http://0.0.0.0:4200. **
63% building modules 469/527 modules 58 active ...s/#angular/compiler/src/assertions.jsKilled
npm info lifecycle angular-test#0.0.0~start: Failed to exec start script
npm ERR! Linux 4.4.0-64-generic
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "start"
npm ERR! node v6.10.3
npm ERR! npm v3.10.10
npm ERR! code ELIFECYCLE
npm ERR! angular-test#0.0.0 start: `ng serve --host 0.0.0.0`
npm ERR! Exit status 137
npm ERR!
npm ERR! Failed at the angular-test#0.0.0 start script 'ng serve --host 0.0.0.0'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the angular-test package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! ng serve --host 0.0.0.0
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs angular-test
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls angular-test
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /usr/src/app/npm-debug.log
Here is my Dockerfile:
# Create image based on the official Node 6 image from dockerhub
FROM node:6
# Create a directory where our app will be placed
RUN mkdir -p /usr/src/app
# Change directory so that our commands run inside this new directory
WORKDIR /usr/src/app
# Copy dependency definitions
COPY package.json /usr/src/app
# Install dependecies
RUN npm install
# Get all the code needed to run the app
COPY . /usr/src/app
# Expose the port the app runs in
EXPOSE 4200
# Serve the app
CMD ["npm", "start"]
How come it runs locally and fails on server? Am I missing some dependencies?
ng serve is an angular-cli command. I'm guessing you need to install it globally in your docker file if you want to start your server like that on digital ocean:
RUN npm i -g angular-cli
I think it would be more typical to simply run the app using the naked node server in production. So your CMD would look more like this:
CMD ["node", "app.js"]

Resources