npm / cli

the package manager for JavaScript
https://docs.npmjs.com/cli/
Other
8.46k stars 3.15k forks source link

[BUG] Version npm@9.1.1 incompatible with Docker when userns-remap feature is enabled #5900

Open isiegl opened 1 year ago

isiegl commented 1 year ago

Is there an existing issue for this?

This issue exists in the latest npm version

Current Behavior

FROM node:18.12.1-alpine AS base
WORKDIR /app
EXPOSE 3000

FROM node:18.12.1-alpine AS build
WORKDIR /src
COPY "FMC.GTMP.Twix.PDP.Web.Mock/Client/src" "temp/src"
COPY "FMC.GTMP.Twix.PDP.Web.Mock/Client/public" "temp/public"
COPY "FMC.GTMP.Twix.PDP.Web.Mock/Client/package.json" "temp/package.json"
COPY "FMC.GTMP.Twix.PDP.Web.Mock/Client/webpack.config.js" "temp/webpack.config.js"
WORKDIR /src/temp
RUN apk update
RUN npm install -g npm@9.1.1
RUN npm install

FROM base AS final
WORKDIR /app
ENV NODE_ENV production
COPY --from=build /src/temp ./

ENTRYPOINT ["npm", "run", "start"]

When enabling the userns-remap Docker feature and installing any NPM version above 9.1.1, the image TAR extraction process fails.

ERROR - failed to register layer: Error processing tar file(exit status 1): Container ID 369884941 cannot be mapped to a host IDErr: 0, Message: failed to register layer: Error processing tar file(exit status 1): Container ID 369884941 cannot be mapped to a host ID

Expected Behavior

The Docker image builds, the docker container starts successfully and the app is shown in the browser.

Steps To Reproduce

  1. Docker engine is running
  2. Enable the docker feature userns-remap
  3. Build the docker image based on the docker file content shared above

Environment

nazario29 commented 1 year ago

In my case I could experience this issue with any of npm 9.x versions, actually tried all of them below 9.1.1. For anyone that is struggling with this issue please follow Qusic workaround 1b7c1f8 🥇

nlf commented 1 year ago

i believe https://github.com/npm/pacote/pull/261 should fix this. will follow up after that lands and ships

NoNameProvided commented 1 year ago

The above-mentioned PR has been merged and included in the 9.5.1 release of NPM.