[BUG] Problems with npm install in docker
Is there an existing issue for this?
- [x] I have searched the existing issues
This issue exists in the latest npm version
- [x] I am using the latest npm
Current Behavior
Simple test application generated with npm init and npm install
I've already tried with node:24 node:22 node:18, I noticed that if I remove express from dependencies the error stops, I don't know if it's because nothing needs to be installed or if the problem is in express
I've tried with and without --no-update-notifier
{
"name": "psvo",
"version": "1.0.0",
"description": "SPA Example",
"license": "ISC",
"author": "",
"type": "module",
"main": "index.js",
"scripts": {
},
"dependencies": {
"express": "^5.1.0"
}
}
In Dockerfile
FROM node:22-alpine
WORKDIR /app
COPY package*.json .
RUN npm install --no-update-notifier
EXPOSE 80
CMD ["npm", "start"]
In docker compose
services:
psvo-dev:
container_name: psvo-dev
build:
context: .
dockerfile: Dockerfile
restart: unless-stopped
volumes:
- /app/node_modules
When running docker compose build, npm install runs for a few minutes and issues the following error:
usuario@server:~/ecosistema1/services/psvo$ docker compose build
[+] Building 148.2s (9/9) FINISHED
=> [internal] load local bake definitions 0.0s
=> => reading from stdin 537B 0.0s
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 207B 0.0s
=> [internal] load metadata for docker.io/library/node:22-alpine 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [1/4] FROM docker.io/library/node:22-alpine 0.0s
=> [internal] load build context 0.0s
=> => transferring context: 72B 0.0s
=> CACHED [2/4] WORKDIR /app 0.0s
=> [3/4] COPY package*.json . 0.2s
=> ERROR [4/4] RUN npm install --no-update-notifier 147.2s
------
> [4/4] RUN npm install --no-update-notifier:
146.5 npm error Exit handler never called!
146.5 npm error This is an error with npm itself. Please report this error at:
146.5 npm error <https://github.com/npm/cli/issues>
146.5 npm error A complete log of this run can be found in: /root/.npm/_logs/2025-09-16T16_05_37_926Z-debug-0.log
------
Dockerfile:7
--------------------
failed to solve: process "/bin/sh -c npm install --no-update-notifier" did not complete successfully: exit code: 1
- I tested with and without the node_modules volume
- I tested with and without --no-update-notifier
What I know now:
-
If I comment out RUN npm install and run the build, it works. After that, I run the container and run npm install inside the container, and it works!
-
For RUN npm install to work, I needed to define the /etc/docker/daemon.json file.
$ cat /etc/docker/daemon.json
{
"dns": ["1.1.1.1", "1.0.0.1"]
}
I'm using Ubuntu 24.04 with a minimized installation + Docker installed via curl as described at https://docs.docker.com/engine/install/ubuntu/