Skip to main content

Use private package on Dockerfile

Expect​

  • Able to build image on Docker using private npm package

How​

  • On Dockerfile add:
ARG NPM_TOKEN
ARG NPM_SCOPE

RUN nl=$'\n' && echo "@$NPM_SCOPE:registry=https://npm.pkg.github.com/ $nl\
//npm.pkg.github.com/:_authToken=$NPM_TOKEN $nl\
" > .npmrc

RUN npm install

RUN rm -f .npmrc

Where:

note

The shell is ignoring the \n when using double quotes and that using single quotes performs no variable expansion

Then, set env:

export NPM_TOKEN=<your token>
export NPM_SCOPE=<scope>

Then, build your docker with command:

docker build -t ab_chat_sdk --build-arg NPM_TOKEN=${NPM_TOKEN} --build-arg NPM_SCOPE=${NPM_SCOPE} .