Building docker image failed because the package.json contains gitlab private package registry

when running :
$ docker build -t temp-image-auth .
im getting the error:

=> ERROR [7/8] RUN npm install 41.6s

[7/8] RUN npm install:
#11 41.40 npm ERR! code E404
#11 41.40 npm ERR! 404 Not Found - GET https://registry.npmjs.org/@my_user_name/private-packages - Not found
#11 41.40 npm ERR! 404
#11 41.40 npm ERR! 404 ‘@my_user_name/private-packages@*’ is not in the npm registry.
#11 41.40 npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
#11 41.40 npm ERR! 404
#11 41.40 npm ERR! 404 Note that you can also install from a
#11 41.40 npm ERR! 404 tarball, folder, http url, or git url.
#11 41.43
#11 41.43 npm ERR! A complete log of this run can be found in:
#11 41.43 npm ERR! /root/.npm/_logs/2022-12-06T16_10_17_903Z-debug.log

my simple dockerfile

FROM node:15.4

WORKDIR /app
COPY package.json .
RUN npm install
COPY . .

CMD npm run start

my simple package.json

{
  "name": "users",
  "version": "0.0.1",
  "description": "",
  "author": "",
  "private": true,
  "license": "UNLICENSED",
  "scripts": {
    "start": "nest start"
  },
  "dependencies": {
    "@my_user_name/private-packages": "*",
    .
    .
    .
    .
  }
}

I found the answer here

npmrc file:

[type or paste code here](//registry.npmjs.org/:_authToken=${NPM_TOKEN})

Dockerfile:

FROM node
ARG NPM_TOKEN  
COPY .npmrc .npmrc  
COPY package.json package.json  
RUN npm install  
RUN rm -f .npmrc
# Add your source files
COPY . .  
CMD npm start

Then run
docker build --build-arg NPM_TOKEN=${NPM_TOKEN} .