Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker blocked on NPM install - Socket Timeout

Tags:

npm

docker

I have a simple Dockerfile which is running node, this is the configuration:

FROM node:latest

WORKDIR /usr/src/auth-starter-server

COPY ./ ./

RUN npm install

CMD ["sh"]

Which is being used on a docker-compose.yml as such:

version: "3.8"

services:
  # Node Server
  auth-starter-server:
    container_name: server
    restart: unless-stopped
    build: ./
    command: npm run start:live
    working_dir: /usr/src/auth-starter-server
    ports:
      - "5000:5000"
    volumes:
      - ./:/usr/src/auth-starter-server

From a day to the other happened I couldn't build the image any longer. It starts without problems,

Creating network "react-auth-starter_default" with the default driver
Building auth-starter-server
Step 1/5 : FROM node:latest
 ---> 6f7f341ab8b8
Step 2/5 : WORKDIR /usr/src/auth-starter-server
 ---> Using cache
 ---> b25f7c08d3eb
Step 3/5 : COPY ./ ./
 ---> Using cache
 ---> 2a06e76bab32
Step 4/5 : RUN npm install
 ---> Running in 0034d6afa38e

but when building with docker-compose up --build (or simply docker build -t auth-starter-server .) it just times out on 'npm install' and it returns the following error:

npm notice 
npm notice New minor version of npm available! 7.0.15 -> 7.3.0
npm notice Changelog: <https://github.com/npm/cli/releases/tag/v7.3.0>
npm notice Run `npm install -g [email protected]` to update!
npm notice 
npm ERR! code ERR_SOCKET_TIMEOUT
npm ERR! errno ERR_SOCKET_TIMEOUT
npm ERR! request to https://registry.companyregistry.com/yargs-parser/-/yargs-parser-13.1.2.tgz failed, reason: Socket timeout

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2020-12-21T15_37_42_509Z-debug.log
ERROR: Service 'auth-starter-server' failed to build : The command '/bin/sh -c npm install' returned a non-zero code: 1

Something I noticed is that's not using the official npm registry, even though that hasn't been set up as the default registry. Here the npm configuration (got by running npm config ls -l):

cli configs
long = true
metrics-registry = "https://registry.npmjs.org/"
scope = ""
user-agent = "npm/6.14.9 node/v15.4.0 darwin x64"

; builtin config undefined
prefix = "/usr/local"

; default values
access = null
allow-same-version = false
also = null
always-auth = false
audit = true
audit-level = "low"
auth-type = "legacy"
before = null
bin-links = true
browser = null
ca = null
cache = "/Users/ale917k/.npm"
cache-lock-retries = 10
cache-lock-stale = 60000
cache-lock-wait = 10000
cache-max = null
cache-min = 10
cafile = undefined
cert = null
cidr = null
color = true
commit-hooks = true
depth = null
description = true
dev = false
dry-run = false
editor = "vi"
engine-strict = false
fetch-retries = 2
fetch-retry-factor = 10
fetch-retry-maxtimeout = 60000
fetch-retry-mintimeout = 10000
force = false
format-package-lock = true
fund = true
git = "git"
git-tag-version = true
global = false
global-style = false
globalconfig = "/usr/local/etc/npmrc"
globalignorefile = "/usr/local/etc/npmignore"
group = 20
ham-it-up = false
heading = "npm"
https-proxy = null
if-present = false
ignore-prepublish = false
ignore-scripts = false
init-author-email = ""
init-author-name = ""
init-author-url = ""
init-license = "ISC"
init-module = "/Users/ale917k/.npm-init.js"
init-version = "1.0.0"
json = false
key = null
legacy-bundling = false
link = false
local-address = undefined
loglevel = "notice"
logs-max = 10
; long = false (overridden)
maxsockets = 50
message = "%s"
; metrics-registry = null (overridden)
node-options = null
node-version = "15.4.0"
noproxy = null
offline = false
onload-script = null
only = null
optional = true
otp = null
package-lock = true
package-lock-only = false
parseable = false
prefer-offline = false
prefer-online = false
; prefix = "/usr/local/Cellar/node/15.4.0" (overridden)
preid = ""
production = false
progress = true
proxy = null
read-only = false
rebuild-bundle = true
registry = "https://registry.npmjs.org/"
rollback = true
save = true
save-bundle = false
save-dev = false
save-exact = false
save-optional = false
save-prefix = "^"
save-prod = false
scope = ""
script-shell = null
scripts-prepend-node-path = "warn-only"
searchexclude = null
searchlimit = 20
searchopts = ""
searchstaleness = 900
send-metrics = false
shell = "/bin/zsh"
shrinkwrap = true
sign-git-commit = false
sign-git-tag = false
sso-poll-frequency = 500
sso-type = "oauth"
strict-ssl = true
tag = "latest"
tag-version-prefix = "v"
timing = false
tmp = "/var/folders/2t/36_q44_s62d1b57hnl0l8khw0000gn/T"
umask = 18
unicode = true
unsafe-perm = true
update-notifier = true
usage = false
user = 0
; user-agent = "npm/{npm-version} node/{node-version} {platform} {arch} {ci}" (overridden)
userconfig = "/Users/ale917k/.npmrc"
version = false
versions = false
viewer = "man"

Can it be the reason why it stopped building is because it's pointing to the wrong registry? And if so, how can that be fixed?

Bit on a side, I noticed as well that warning regarding the npm update; How can I update the npm package inside a docker image?

Any answer is highly appreciated, so thank you for your inputs!

like image 885
ale917k Avatar asked Apr 07 '26 12:04

ale917k


2 Answers

Found out my company's server went down, bringing down related registries and similar.

That resulted in not being able to process the package installation, as for some reason I seemed to have dependency leftovers from the company custom registry.

In order to fix this, I:

  1. Firstly created different npmrc profiles, to make sure we use the appropriate registry when working on a specific project - Ref can be found here

  2. Have then deleted node_modules and package-lock.json to cleanup leftovers

  3. Set the profile pointing to the open-source registry (https://registry.npmjs.org/) with npmrc <profile>

  4. (Optional): Check active registry profile by simply running npmrc

  5. Reinstalled all packages with npm install

  6. Rebuild docker-image with docker-compose up --build and that made the job

Hope this may help other people in the future

like image 100
ale917k Avatar answered Apr 10 '26 03:04

ale917k


I have been encountering this same issue and later realized that I had a bad network connection which caused the ERR_SOCKET_TIMEOUT.

Its not due to Run npm install -g [email protected] to update!`. As you can see below its still up and running

enter image description here

like image 39
Shanka Somasiri Avatar answered Apr 10 '26 02:04

Shanka Somasiri



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!