docker-node: NPM install stucks with node:20
Environment
- Platform: MacOS Ventura (13.4.1) on M1
- Docker Version: 24.0.5
- Node.js Version: 20
- Image Tag: 20
Expected Behavior
NPM install should be started. I’ve tested this with node:18 image instead and it works. node:20-slim stucks too.
Current Behavior
NPM install does not start and stucks.
[test] docker build --progress=plain --platform linux/amd64 -t test-image . 9:52:01
#0 building with "desktop-linux" instance using docker driver
#1 [internal] load .dockerignore
#1 transferring context: 66B done
#1 DONE 0.0s
#2 [internal] load build definition from Dockerfile
#2 transferring dockerfile: 414B done
#2 DONE 0.0s
#3 [internal] load metadata for docker.io/library/node:20
#3 DONE 1.3s
#4 [1/5] FROM docker.io/library/node:20@sha256:64b71834718b859ea389790ae56e5f2f8fa9456bf3821ff75fa28a87a09cbc09
#4 CACHED
#5 [2/5] WORKDIR /usr/src/app
#5 DONE 0.0s
#6 [internal] load build context
#6 transferring context: 1.12kB 0.0s done
#6 DONE 0.0s
#7 [3/5] COPY package*.json ./
#7 DONE 0.0s
#8 [4/5] RUN npm install
I’ve tried other npm commands like npm cache clean --force
but those stuck too.
Possible Solution
Steps to Reproduce
I’m using the docker file from official nodejs example :
FROM node:20
# Create app directory
WORKDIR /usr/src/app
# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
COPY package*.json ./
RUN npm install
# If you are building your code for production
# RUN npm ci --omit=dev
# Bundle app source
COPY . .
EXPOSE 8080
CMD [ "node", "server.js" ]
Additional Information
About this issue
- Original URL
- State: open
- Created a year ago
- Reactions: 24
- Comments: 17 (2 by maintainers)
Commits related to this issue
- fix: arm ci/cd build with node20 # linux/arm/v7 arm32 is not supported by node20 https://github.com/nodejs/docker-node/issues/1946 — committed to Ravinou/borgwarehouse by Ravinou 5 months ago
- Revert node upgrade See https://github.com/nodejs/docker-node/issues/1946 — committed to terralist/terralist by valentindeaconu 2 months ago
- chore: Upgrade stack versions (#228) * chore: Upgrade stack versions * Revert node upgrade See https://github.com/nodejs/docker-node/issues/1946 — committed to terralist/terralist by valentindeaconu 2 months ago
- fix build on mac m1 https://github.com/nodejs/docker-node/issues/1946 — committed to cooperaj/kingtrashmouth by cooperaj 2 months ago
I’m encountering the same issue - docker build hangs on
RUN npm install
. The problem occurs when trying to build an image using--platform=linux/amd64
on Docker Desktop Mac.(Why do this? I want to test an image on my mac laptop that will eventually run in an amd64 environment, and one apt dependency does not have an arm64 version)
Workarounds I found:
Dockerfile
package.json
index.js
Console output
Same issue affecting npm and yarn when using
docker buildx
and building for linux/arm/v7got same issues , you can easily duplicate this issue with below commands
Then it stucks at installation forever.
run tests on below platforms
linux/amd64
,linux/arm64/v8
,linux/ppc64le
buildx
hangs on problem:linux/s390x
,inux/arm/v6
,linux/arm/v7
I have the same issue with yarn
Trigger
What triggered this problem for me was updating my
package-lock.json
from version 1 to version 3.Solution
The key solution for me was using
npm install --no-audit
, which also just makes it run much faster, and auditing can probably just be done independently of the normal build/CI process.Details
Here are some additional details I gathered before finding the final solution, in case it’s helpful for others, or for debugging the root problem.
Sorta Solutions
These attempts somewhat worked but not in a satisfactory way…
Reverting back to my version 1
package-lock.json
file worked, but I didn’t want to stick with this because it felt fragile and it was slow because npm had to recreate it each time I ran my docker-based build (unless in the docker cache).For 1 code repository, it worked to remove the
package-lock.json
file and recreate it, but this didn’t work for my other repo.Non-Solutions
These attempts didn’t work…
Installing the latest LTS
node
currently 20.11.1 which containsnpm
version 10.2.4Deleting and recreating my
package-lock.json
(although it worked for the 1 repo mentioned above)Using
docker build --network=host
I was able to run yarn and npm commands now after disabling Use Rosetta for x86/amd64 emulation on Apple Silicon option in docker settings. Not sure this is a fix.
Same here. My image works with Node 16, 18 and 19. With 20 even
corepack enable
command gets stuckUpdate: on my pipeline based on Ubuntu-22.04 linux/amd64 works