基于docker-compose+verdaccio搭建自己的npm仓库(离线部署)

# 目录结构

└── /verdaccio 项目目录
   ├──/conf 配置目录
   │  └── config.yaml verdaccio 配置文件
   │  └── htpasswd 用户密码文件
   │
   ├──/storage 包存放目录
   │
   └── docker-compose.yml docker-compose配置文件

 

第一步:创建docker-compose.yml文件

version: '3'

services:
  verdaccio:
    image: verdaccio/verdaccio:4
    container_name: verdaccio
    ports:
      - 4873:4873
    volumes:
      - ./conf/:/verdaccio/conf/
      - ./plugins/:/verdaccio/plugins/
      - ./storage/:/verdaccio/storage/

networks:
  default:
    external:
      name: sa_network

第二步:创建config.yaml配置文件

# 所有包的缓存目录
storage: /verdaccio/storage/
# 插件目录
plugins: /verdaccio/storage/
#开启web 服务,能够通过web 访问
web:
  # WebUI is enabled as default, if you want disable it, just uncomment this line
  enable: true
  title: Sinux-Npm-Register #网站首页进入的正文标题
  # logo: #这里可以给定一个远程连接的图片,注释掉就采用默认的
  # comment out to disable gravatar support
  gravatar: true
  # by default packages are ordercer ascendant (asc|desc)
  # sort_packages: asc  # 包的排序
  # darkMode: true # 黑暗模式
  # scope: "@scope"
auth:
  htpasswd:
    # 用户信息存储目录
    file: ./htpasswd
    #此配置项可以关闭注册功能
    max_users: -1 
i18n:
# list of the available translations https://github.com/verdaccio/ui/tree/master/i18n/translations
  web: zh-CN # 默认是en-US,我们改为默认中文,这个东东支持多语言
uplinks:
  npmjs:
    url: https://registry.npmjs.org/
  yarn:
    url: https://registry.yarnpkg.com/
    timeout: 10s
  taobao:
    url: https://registry.npm.taobao.org/
    timeout: 10s
packages:
  "@*/*":
    # 三种身份,所有人,匿名用户,认证(登陆)用户
    # "$all", "$anonymous", "$authenticated"
    access: $all
    #发布package 的权限
    publish: $all
    proxy: npmjs
  "**":
    access: $all
    publish: $all
    proxy: npmjs yarn  taobao
# To use `npm audit` uncomment the following section
middlewares:
  audit:
    enabled: true
# 监听的端口 ,重点, 不配置这个,只能本机能访问
listen: 0.0.0.0:4873
logs:
  - { type: stdout, format: pretty, level: http }

第三步:创建用户文件htpasswd  (如:用户名demo、密码:123456 密码需要MD5加密)

demo:$apr1$qsy657ob$513Jt6hccMym6l4mPFkF80

密码生成可参考: https://hostingcanada.org/htpasswd-generator/

 

第四步 : 构建启动

# 后台构建
$ docker-compose up -d


# 停止并删除构建
$ docker-compose down

 

第五步:使用

// 访问
http://127.0.0.1:4873


# 添加用户
$ npm adduser --registry  http://127.0.0.1:4873

# 登录
$ npm login

# 推送
npm publish --registry http://127.0.0.1:4873

 

注意:需要注意目录结构

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

子兮曰

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值