[英]Install package from private registry using Yarn in Docker
I try to install packages from a private registry using yarn in a docker image, so we reuse this image in other pipelines.我尝试使用 docker 映像中的纱线从私有注册表安装包,因此我们在其他管道中重用此映像。 When I use npm everything works fine, but as soon I use yarn i get 404's.当我使用 npm 时,一切正常,但是一旦我使用纱线,我就会得到 404。
Using NPM it is working fine:使用 NPM 它工作正常:
RUN npm config set @my-scope:registry https://registry.npmjs.org && \
npm config set //registry.npmjs.org:_authToken ${AUTH_TOKEN_PRIVATE_REGISTRY}
RUN npm i @my-scope/my-package # success!
And when using Yarn:使用纱线时:
RUN yarn config set @my-scope:registry https://registry.npmjs.org && \
yarn config set //registry.npmjs.org:_authToken ${AUTH_TOKEN_PRIVATE_REGISTRY}
RUN yarn add @my-scope/my-package # 404!
I'm really wondering what I'm doing wrong when using Yarn.我真的很想知道我在使用 Yarn 时做错了什么。 I see quite some options to login via the CLI, which will work but I need to have the process automated.我看到很多通过 CLI 登录的选项,它们可以工作,但我需要使过程自动化。
After some trials I solved it by adding 2 files: the .yarnrc
and .npmrc
.经过一些试验,我通过添加 2 个文件来解决它: .yarnrc
和.npmrc
。
The .yarnrc
contains the following: .yarnrc
包含以下内容:
registry "https://registry.npmjs.org"
The .npmrc
contains: .npmrc
包含:
//registry.npmjs.org/:_authToken=[ACCESS_TOKEN]
You can now remove the yarn config set
lines from Docker, and run yarn add @my-scope/foo-bar
to install your package.您现在可以从 Docker 中删除yarn config set
行,然后运行yarn add @my-scope/foo-bar
来安装您的 package。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.