使用Verdaccio(docker)搭建私有npm仓库

使用Verdaccio(docker)搭建私有npm仓库

一、概述

Verdaccio可以帮我们搭建npm私有仓库,配合docker更加方便

二、安装
  1. 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"
    
  2. 配置: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包管理:详细配置

  1. 权限

    verdaccio 容器中创建的用户是verdaccio,无法写入主机 root 用户的文件,容器内 verdaccio 使用的 uid 为 10001,gid 为 65533,可以在主机修改权限

    sudo chown 10001:65533 htpasswd
    sudo chown -R 10001:65533 storage
    
三、使用
  1. 注册用户

    npm adduser --registry http://ip:4873
    
  2. 发布

    • package.json

        "publishConfig": {
          "registry": "http://ip:4873"
        },
      
  3. 自动源

    • .npmrc

      @xxx:registry=http://ip:4873/
      
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值