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[0m[91m
[0m[91mnpm ERR! code ERR_SOCKET_TIMEOUT
[0m[91mnpm ERR! network Socket timeout
npm [0m[91mERR! network This is a problem related to network connectivity.
npm[0m[91m ERR! [0m[91mnetwork In most cases you are behind a proxy or have bad network settings.
npm ERR! [0m[91mnetwork
npm ERR![0m[91m network If you are behind a proxy, please make sure that the
[0m[91mnpm[0m[91m [0m[91mERR! network[0m[91m 'proxy' config is set properly. See: 'npm help config'
[0m[91m
[0m[91mnpm 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)
To me, it was solved by npm upgrade and sockets limit:
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 usenode:14-alpine
rather thannode:16-alpine
then I don’t receive the error and thenpm 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
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
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 installnodejs-current@18.6.0-r0
andnpm@8.10.0-r0
. I even tried to update it usingnpm -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
Same thing. Works well with
node:alpine
but fails withnode: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.
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.