使用Verdaccio(docker)搭建私有npm仓库
一、概述
Verdaccio可以帮我们搭建npm私有仓库,配合docker更加方便
二、安装
-
docker-compose
version: '3.5' services: verdaccio: image: verdaccio/verdaccio container_name: "verdaccio" restart: always environment: - VERDACCIO_PORT=4873 ports: - "4873:4873" volumes: - "./storage:/verdaccio/storage" - "./config:/verdaccio/conf" - "./plugins:/verdaccio/plugins"
-
配置:config.yaml
storage: /verdaccio/storage plugins: /verdaccio/plugins web: enable: true title: xxnpm仓库 primary_color: red i18n: web: zh-CN auth: htpasswd: file: /verdaccio/conf/htpasswd security: api: jwt: sign: expiresIn: 60d notBefore: 1 web: sign: expiresIn: 7d ## IMPORTANT ## This will configure verdaccio to rely on a relative path # url_prefix: /verdaccio/ uplinks: npmjs: url: https://registry.npmjs.org/ cnpm: url: http://r.cnpmjs.org/ packages: "@xxx/*": access: $authenticated publish: $authenticated unpublish: $authenticated "@*/*": access: $all publish: $authenticated unpublish: $authenticated proxy: cnpm "**": access: $all publish: $authenticated unpublish: $authenticated proxy: cnpm middlewares: audit: enabled: true logs: { type: stdout, format: pretty, level: trace } listen: 0.0.0.0:4873
-
htpasswd
文件:用来存储 npm 用户及密码user001:xxx:autocreated 2022-01-01T00:00:00Z user002:xxx:autocreated 2022-01-01T00:00:00Z
-
security
安全:配置token -
uplinks
上游源:当前仓库没有的package就会从配置的源下载 -
packages
包管理:详细配置
-
权限
verdaccio 容器中创建的用户是verdaccio,无法写入主机 root 用户的文件,容器内 verdaccio 使用的 uid 为
10001
,gid 为65533
,可以在主机修改权限sudo chown 10001:65533 htpasswd sudo chown -R 10001:65533 storage
三、使用
-
注册用户
npm adduser --registry http://ip:4873
-
发布
-
package.json
"publishConfig": { "registry": "http://ip:4873" },
-
-
自动源
-
.npmrc
@xxx:registry=http://ip:4873/
-