Currently use my own private npm.
In my local, i always need to login to my own private npm first and install all the packages to my project
npm login --registry https://nodenpm.XXXX.co # to login private npm registry
> Enter username
> Enter password
npm install --registry https://nodenpm.XXXX.co # to install the deps from private registry
In the dockerfile, how do I log in to my own private npm and install?
This is my docker file
FROM ubuntu:22.04
WORKDIR /app
RUN npm login --registry=https://nodenpm.XXXX.co -u <username> -p <password>
RUN npm install --registry https://nodenpm.XXXX.co --save
RUN npm run build
EXPOSE 80
CMD [ "node", "/app/dist/main" ]
But it has fail to build in docker
2
Answers
Thank you @Branyac and based on his answer.
Make sure you have .npmrc file
In my docker file, I removed all the login info and added
Then in the CMD run
It’s not recommended to include user and password credentials directly inside a Dockerfile due to security risks. Instead, you should store npm registry credentials in the
.npmrc
1 file.You should remove
npm login
from your dockerfile and mount the .npmrc file as a Docker secret in the correct path (Typically, the npmrc file is located at $HOME/.npmrc).