1

I have an angular package in a private npm in azure and I need to install it in a docker. I don't know how to get an authentication token to connect to the private npm, I have .npmrc file.

My docker

FROM node:latest AS build
 
RUN mkdir -p /app

WORKDIR /app

COPY package.json /app

COPY .npmrc .npmrc
   
RUN npm install https://myprivate-npm/npm/registry/:_authToken=${NPM_TOKEN}

RUN npm install

When I installed it locally, I ran these two commands from VS Code and they did the job

npm install -g vsts-npm-auth --registry https://registry.npmjs.com --always-auth false    
vsts-npm-auth -config .npmrc
2
  • 1
    are you passing an ARG with an access token into your docker build command? Also your `myprivate-npm/npm/registry/:_authToken=${NPM_TOKEN} can just go in the .npmrc file Commented Jun 28, 2021 at 15:14
  • No, I don't know how to get an access token in docker. Commented Jun 28, 2021 at 19:53

1 Answer 1

2

To get an access token in docker:

Amend your .npmrc file with the following contents:

//registry.npmjs.org/:_authToken=${NPM_TOKEN}

Amend your dockerfile:

FROM node:latest AS build
ARG NPM_TOKEN
RUN mkdir -p /app
WORKDIR /app
COPY package.json /app
COPY .npmrc .npmrc
RUN npm install
RUN rm -f .npmrc

Build your image replacing ${NPM_TOKEN} with your npm token docker build --build-arg NPM_TOKEN=${NPM_TOKEN} .

Everything here can be found in the NPM documentation

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you but from where should I get this value NPM_TOKEN?
you can create access tokens using your npm account. Its one of the options in your profile area

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.