npm通过verdaccio搭建私服镜像库,以此提高本地多人协同install速度。verdaccio安装方式选为docker方式。
docker相关知识可以查看往期相关文章:
首先是配置 docker-compose.yml配置
version: "3.8" networks: vRouter: external: false services: verdaccio: image: verdaccio/verdaccio:5.30.3 container_name: verdaccio restart: always volumes: - ./conf:/verdaccio/conf - ./storage/:/verdaccio/storage - ./plugins:/verdaccio/plugins ports: - '7749:4873' networks: vRouter: aliases: - verdaccio.server deploy: resources: limits: memory: 300M
注意:上方配置将verdaccio默认端口4873映射到了主机7749上
上传docker-compose.yml到目录 /opt/docker/verdaccio下,并在该目录下创建conf storage plugins 三个目录,且赋权777解决一些莫名其妙的docker内部权限不足问题。
mkdir -p /opt/docker/verdaccio cd /opt/docker/verdaccio mkdir conf storage plugins chmod 777 -R conf storage plugins
在conf创建verdaccio默认配置文件config.yaml,内容参考如下:
# # This is the config file used for the docker images. # It allows all users to do anything, so don't use it on production systems. # # Do not configure host and port under `listen` in this file # as it will be ignored when using docker. # see https://github.com/verdaccio/verdaccio/blob/master/wiki/docker.md#docker-and-custom-port-configuration # # Look here for more config file examples: # https://github.com/verdaccio/verdaccio/tree/master/packages/config/src/conf # # path to a directory with all packages storage: /verdaccio/storage auth: htpasswd: file: /verdaccio/conf/htpasswd # Maximum amount of users allowed to register, defaults to "+inf". # You can set this to -1 to disable registration. #max_users: 1000 #[modify by xqlee] max_users: -1 security: api: jwt: sign: expiresIn: 60d notBefore: 1 web: sign: expiresIn: 7d # a list of other known repositories we can talk to uplinks: npmjs: url: https://registry.npmjs.org/ taobao: url: https://registry.npmmirror.com/ packages: '@jota/*': access: $all publish: $all '@*/*': # scoped packages access: $all publish: $all proxy: taobao npmjs '**': # allow all users (including non-authenticated users) to read and # publish all packages # # you can specify usernames/groupnames (depending on your auth plugin) # and three keywords: "$all", "$anonymous", "$authenticated" #[modify by xqlee] access: $anonymous # allow all known users to publish packages # (anyone can register by default, remember?) publish: $all # if package is not available locally, proxy requests to 'npmjs' registry proxy: npmjs # To use `npm audit` uncomment the following section middlewares: audit: enabled: true # log settings log: - { type: stdout, format: pretty, level: trace } #- {type: file, path: verdaccio.log, level: info}
文档参考官方的,做了几处修改分别标记了#[modify by xqlee]
access: $anonymous
由之前的access: $all
修改的,默认的$all表示所有用户,我这里需要匿名访问,不需要用户所以配置了$anonymous
作为镜像完全够了
配置文件也记得改成777
chmod 777 config.yml
返回/opt/docker/verdaccio 目录启动
sudo docker-compose up -d
启动完成后通过主机ip:端口访问
点配置齿轮可以修改默认的语言和查看如何配置仓库,参考:
重要提示:由于js文件小巧且npm依赖一般多,所以比较耗费硬盘io资源,建议独立部署镜像应用。或找一个SSD的硬盘部署,防止io过高导致系统boom哟
verdaccio的更多私服功能如用户上传自己的库等后续再更...
http://blog.xqlee.com/article/2404131124399972.html