[英]Authenticate npm private registry in docker
We're publishing scoped js packages to a private registry (managed by us using Verdaccio).我们将作用域 js 包发布到私有注册表(由我们使用 Verdaccio 管理)。
It means that in our production environment, we need to authenticate to our private registry to use yarn install
.这意味着在我们的生产环境中,我们需要对我们的私有注册表进行身份验证才能使用yarn install
。 What's the easiest way to do it?最简单的方法是什么?
yarnPath: ".yarn/releases/yarn-berry.cjs"
nodeLinker: node-modules
npmScopes:
customScope:
npmRegistryServer: ${NPM_REGISTRY}
npmAlwaysAuth: true
npmAuthToken: ${NPM_TOKEN}
#docker-compose.yml
version: '3.7'
services:
server:
image: node:14
environment:
NPM_REGISTRY=https://private-registry
NPM_TOKEN=PUT_YOUR_TOKEN_HERE
ports:
- "3000:3000"
volumes:
- .:/var/app
command: "yarn run dev"
You can also put env vars in a .env
file and add it to .gitignore
您还可以将环境变量放在.env
文件中并将其添加到.gitignore
Add a scoped package添加范围 package
docker-compose run --rm server yarn add @customScope/test-package
Install安装
docker-compose run --rm server yarn install
If you can't or don't want to use .env
file, but you already have .yarnrc.yml
file with your registry url like that:如果您不能或不想使用.env
文件,但您的注册表 url 已经有.yarnrc.yml
文件,如下所示:
npmScopes:
yourScopeName:
npmRegistryServer: 'https://...'
then you can use yarn config set
command to add npmAuthToken
key with your token value, for example:然后您可以使用yarn config set
命令添加带有令牌值的npmAuthToken
键,例如:
// $REGISTRY_TOKEN is an ARG variable you pass to Docker
ARG REGISTRY_TOKEN
RUN yarn config set 'npmScopes.yourScopeName.npmAuthToken' "$REGISTRY_TOKEN"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.