docker-node: npm install in docker scoket timeout

https://github.com/laradock/laradock/issues/2843#issuecomment-972524249 should i report this problem at here? it happend when I use node:lts-alpine

here is my dockerfile

# build stage
FROM node:lts-alpine as build-stage
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY ./ .
RUN npm run lint
RUN npm run dockerbuild
......

and it will cause

......
npm notice New minor version of npm available! 8.3.1 -> 8.5.4
npm notice Changelog: <https://github.com/npm/cli/releases/tag/v8.5.4>
npm notice Run `npm install -g npm@8.5.4` to update!
npm notice 
npm ERR! code ERR_SOCKET_TIMEOUT
npm ERR! network Socket timeout
npm ERR! network This is a problem related to network connectivity.
npm ERR! network In most cases you are behind a proxy or have bad network settings.
npm ERR! network 
npm ERR! network If you are behind a proxy, please make sure that the
npm ERR! network 'proxy' config is set properly.  See: 'npm help config'

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2022-03-16T01_15_11_514Z-debug-0.log
......

here is my dependencies

"dependencies": {
    "@line/liff": "2.12.0",
    "axios": "^0.21.1",
    "bootstrap": "^4.6.0",
    "bootstrap-vue": "^2.21.2",
    "compression-webpack-plugin": "^6.1.1",
    "core-js": "^3.8.3",
    "crypto-js": "^3.3.0",
    "google-libphonenumber": "^3.2.16",
    "qs": "^6.9.4",
    "rxjs": "^7.5.5",
    "sha1": "^1.1.1",
    "vconsole": "^3.4.0",
    "vue": "^2.6.12",
    "vue-i18n": "^8.22.4",
    "vue-router": "^3.5.1",
    "vue-rx": "^6.2.0",
    "vue2-perfect-scrollbar": "^1.5.0",
    "vuex": "^3.6.0"
  },
  "devDependencies": {
    "@vue/cli-plugin-babel": "^4.5.11",
    "@vue/cli-plugin-eslint": "^4.5.11",
    "@vue/cli-plugin-unit-jest": "^4.5.11",
    "@vue/cli-service": "^4.5.11",
    "@vue/eslint-config-airbnb": "^4.0.0",
    "@vue/test-utils": "1.0.0-beta.29",
    "babel-eslint": "^10.0.3",
    "eslint": "^5.16.0",
    "eslint-plugin-vue": "^5.0.0",
    "flush-promises": "^1.0.2",
    "vue-template-compiler": "^2.6.12"
  }

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 10
  • Comments: 23 (1 by maintainers)

Most upvoted comments

To me, it was solved by npm upgrade and sockets limit:

RUN npm update -g npm
RUN npm ci --no-audit --maxsockets 1

I fixed this issue by removing ipv6 from /etc/docker/daemon.json.

So if you don’t have ipv6 you should remove it or if you have ipv6 check if you see the correct ipv6 address

If you make changes to this file you need to restart the service: sudo service docker restart

I can consistently reproduce this - I’ve found that if you only have a few deps then it seems fine, but larger lists of dependencies produce the ERR_SOCKET_TIMEOUT error. If I use node:14-alpine rather than node:16-alpine then I don’t receive the error and the npm install (and container build) succeeds, consistently (I’ve wiped my images between each build to make sure).

💡 Here’s a repo to allow reproducing this: https://github.com/itsravenous/docker-node-repro 💡

I’m sure it could be specific to the network conditions on my machine, or something to do with my Docker setup, but it seems weird that switching to 14 would consistently avoid the issue in that case.

Be interesting to see if others can reproduce using my test case repo - @bbkysf and @x900603 could you confirm?

In the meantime, I’ll try removing deps from that repo’s package.json to see if there’s any particular packages that are causing trouble, or any rough “size” of the dependency list that makes a difference. Not very scientific, I know, but not sure how else to proceed - all a bit over my head I’m afraid 😃

same problem

To me, it was solved by npm upgrade and sockets limit:

RUN npm update -g npm
RUN npm ci --no-audit --maxsockets 1

This solution helped me as well. Nothing else worked. It seems that npm update message returning code 1 in docker brakes build process.

Below is my error output when using node:lts-alpine

 => ERROR [build 5/5] RUN npm install                                                                                   142.4s 
------
 > [build 5/5] RUN npm install:
142.3 npm notice
142.3 npm notice New minor version of npm available! 10.2.4 -> 10.4.0
142.3 npm notice Changelog: <https://github.com/npm/cli/releases/tag/v10.4.0>
142.3 npm notice Run `npm install -g npm@10.4.0` to update!
142.3 npm notice
142.3 npm ERR! code ECONNRESET
142.3 npm ERR! errno ECONNRESET
142.3 npm ERR! network request to https://registry.npmjs.org/yargs-parser/-/yargs-parser-21.1.1.tgz failed, reason: Client network socket disconnected before secure TLS connection was established
142.3 npm ERR! network This is a problem related to network connectivity.
142.3 npm ERR! network In most cases you are behind a proxy or have bad network settings.
142.3 npm ERR! network
142.3 npm ERR! network If you are behind a proxy, please make sure that the
142.3 npm ERR! network 'proxy' config is set properly.  See: 'npm help config'

So maybe this bugfix PR fixed the behaviour

For me, using --maxsockets 1 (as @nlf suggested) worked the issue around. It is too slow though, but it works.

It always worked on my local computer, however it always failed on remote server (I used a VPN to connect to it).

I wanted to build an image from Dockerfile based on alpine:3.16.2 on which I install nodejs-current@18.6.0-r0 and npm@8.10.0-r0. I even tried to update it using npm -g i npm@8.17.0), however it didn’t work.

For now, I use (npm ci --no-audit || npm ci --no-audit --maxsockets 1) as a workaround, albeit when the first command fails, it takes much longer to start the second command, as the first command hangs for about a minute before it fails.

Using this solved it for me

RUN npm cache clean --force && \
    npm install -g npm@latest && \
    npm install

Same thing. Works well with node:alpine but fails with node:16-alpine

EDIT: I am not 100% confident that this is related to :16-alpine specifically, maybe it is more sensitive to bad network, but the network I am currently on is not as reliable as the one I am usually using.

node    alpine           sha256:0677e437543d10f6cb050d92c792a14e5eb84340e3d5b4c25a88baa723d8a4ae   9f58095cfeb6   2 weeks ago          172MB
node    16-alpine        sha256:1a9a71ea86aad332aa7740316d4111ee1bd4e890df47d3b5eff3e5bded3b3d10   e5065cc78074   5 weeks ago          112MB
Step 13/19 : RUN     npm ci
 ---> Running in a8aad4c114bd
npm notice 
npm notice New minor version of npm available! 8.5.5 -> 8.12.1                           
npm notice Changelog: <https://github.com/npm/cli/releases/tag/v8.12.1>                  
npm notice Run `npm install -g npm@8.12.1` to update!                                    
npm notice                                                                               
npm ERR! code ERR_SOCKET_TIMEOUT                                                         
npm ERR! network Socket timeout                                                          
npm ERR! network This is a problem related to network connectivity.                      
npm ERR! network In most cases you are behind a proxy or have bad network settings.      
npm ERR! network                                                                         
npm ERR! network If you are behind a proxy, please make sure that the                    
npm ERR! network 'proxy' config is set properly.  See: 'npm help config'                 
                                                                                         
npm ERR! A complete log of this run can be found in:                                     
npm ERR!     /root/.npm/_logs/2022-06-04T15_32_55_742Z-debug-0.log                       
The command '/bin/sh -c npm ci' returned a non-zero code: 1   
...
914 verbose stack Error: Socket timeout                                                  
914 verbose stack     at TLSSocket.onTimeout (/usr/local/lib/node_modules/npm/node_modules/agentkeepalive/lib/agent.js:346:23)                                                    
914 verbose stack     at TLSSocket.emit (node:events:539:35)                             
914 verbose stack     at TLSSocket.Socket._onTimeout (node:net:516:8)                    
914 verbose stack     at listOnTimeout (node:internal/timers:559:17)                     
914 verbose stack     at processTimers (node:internal/timers:502:7)                      
915 verbose cwd /app                                                                     
916 verbose Linux 5.4.0-113-generic                                                      
917 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "ci"                         
918 verbose node v16.15.0                                                                
919 verbose npm  v8.5.5                                                                  
920 error code ERR_SOCKET_TIMEOUT                                                        
921 error network Socket timeout                                                         
922 error network This is a problem related to network connectivity.                     
922 error network In most cases you are behind a proxy or have bad network settings.     
922 error network                                                                        
922 error network If you are behind a proxy, please make sure that the                   
922 error network 'proxy' config is set properly.  See: 'npm help config'                
923 verbose exit 1                                                                       
924 timing npm Completed in 63573ms                                                      
...

Node 14 and Node 16 ship with different versions of NPM, so the difference is likely there.

Good point. I should clarify that this problem doesn’t occur with node 16 outside of docker.

Node 14 and Node 16 ship with different versions of NPM, so the difference is likely there.